## 10608 Why RE??

Write here if you have problems with your C source code

Moderator: Board moderators

### 10608 Why RE??

I can not understand why RE!
Code: Select all
`#include<stdio.h>#define size 31000bool adj_mat[size][size],visited[size]; main(){        long n,node,con_no,a,b,i,dequeue,counter,tp,friends;    scanf("%ld",&n);    while(n--)    {        scanf("%ld %ld",&node,&con_no);        if(con_no==0)            printf("0\n");        else        {        adj_mat[size][size]={0},visited[size]={0};        long arr[size]={0};        while(con_no>=1)        {            scanf("%ld %ld",&a,&b);            if(adj_mat[b][a]==0)            adj_mat[a][b]=1;            con_no--;        }        friends=0;        for(int k=1;k<=node;k++)        {            i=1,arr[1]=k,counter=1,tp=1;            while(1)            {                dequeue=arr[i];                if(dequeue==0) break;                if(visited[i]==0)                {                    for(int j=1;j<=node;j++)                    {                        if(adj_mat[dequeue][j]==1)                        {                            counter++;                            visited[j]=1;                            arr[tp++]=j;                        }                    }                    visited[i]=0;                }                if(friends<counter) friends=counter;                i++;            }        }       printf("%ld\n",friends); }    }    return 0;}`
Last edited by cse.mehedi on Fri May 25, 2012 2:09 pm, edited 6 times in total.
cse.mehedi
New poster

Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10608 Why RE??

if you declare a_mat of size c then you can only access up to c-1.

You're getting a seg fault during the sample input on line 16: a_mat[i][j]=0;
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10608 Why RE??

brianfry713 wrote:if you declare a_mat of size c then you can only access up to c-1.

You're getting a seg fault during the sample input on line 16: a_mat[i][j]=0;

I could not understand what should i do here "a_mat[i][j]=0".
cse.mehedi
New poster

Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10608 Why RE??

You fixed the issue you were having before, trying to access beyond the limit of the array. Now I think you might be getting RE because you are trying put too much memory on the stack. Instead of declaring a huge local array long a_mat[c+1][c+1] where c can be up to 30000, and the values are only 0 or 1, try using a global bool array in c++.

This input causes your code to seg fault on my machine:
Code: Select all
`130000 0`
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10608 Why RE??

brianfry713 wrote:You fixed the issue you were having before, trying to access beyond the limit of the array. Now I think you might be getting RE because you are trying put too much memory on the stack. Instead of declaring a huge local array long a_mat[c+1][c+1] where c can be up to 30000, and the values are only 0 or 1, try using a global bool array in c++.

This input causes your code to seg fault on my machine:
Code: Select all
`130000 0`

Getting WA!
cse.mehedi
New poster

Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10608 Why RE??

Input:
Code: Select all
`12 11 2`

AC Output:
Code: Select all
`2`
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10608 Why RE??

TLE!!!!!
cse.mehedi
New poster

Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10608 Why RE??

Input:
Code: Select all
`22 11 22 11 2`

AC output:
Code: Select all
`22`
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10608 Why RE??

brianfry713 wrote:Input:
Code: Select all
`22 11 22 11 2`

AC output:
Code: Select all
`22`

TLE!!!!!!!!!
cse.mehedi
New poster

Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10608 Why RE??

Input:
Code: Select all
`22 11 23 12 3`

AC Output:
Code: Select all
`22`
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

### Re: 10608 Why RE??

I modified my code but i am getting RE
cse.mehedi
New poster

Posts: 36
Joined: Sun Mar 18, 2012 8:18 am

### Re: 10608 Why RE??

This won't compile on my system.
You have these globals defined:
This isn't a declaration:
To clear an array using ={0} you must do it at declaration. You could try using memset() instead.
brianfry713
Guru

Posts: 1742
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA