THE BICKERING TASKFORCE( IARCS PROBLEM)

Hi all,

   I have send a code as the solution of TASKFORCE in the ICO online Judge. I am scoring 50 out of 100. In 5 test cases, it is showing segmentation fault. Please tell me why is it showing so. My code:


   #include<iostream> 
   using namespace std; 
   int main()
   {
   long long int peo,hate,k,x,y,c=0;
   cin>>peo>>hate>>k;
   long long int graph[peo+1][peo+1],hatred[peo+1];
   for(long long int i=1;i<=peo;i++)
   {
   for(long long int j=1;j<=peo;j++)
   graph[i][j]=0;
   hatred[i]=0;
   }
   for(long long int i=1;i<=hate;i++)
   {
   cin>>x>>y;
   graph[x][y]=1;
   graph[y][x]=1;
   hatred[x]++;
   hatred[y]++;
   }
   sos:for(long long int i=1;i<=peo;i++)
  {
  if(hatred[i]<=0 || hatred[i]>=k)
  continue;
  else
  {
  for(long long int j=1;j<=peo;j++)
  {
  if(graph[i][j]==1)
  hatred[j]--;
  }
  hatred[i]=0;
  goto sos;
  }
  }
  for(long long int i=1;i<=peo;i++)
  {
  if(hatred[i]>=k)
  c++;
  }
  if(c>0)
  cout<<"YES"<<endl<<c<<endl;
  else
  cout<<"NO"<<endl;
  return 0; 
  }

PLEASE REPLY SOON.

On first sight, your graph adjacency matrix is too large for the local scope. Try making it global. Also, it is a good idea to implement this using an adjacency list as well.

1 Like