What is the problem in my code BUGLIFE — A Bug’s Life spoj?

Revision en3, by optimus2409, 2020-10-06 21:56:03

include <bits/stdc++.h>

using namespace std;

bool isb(vector& visited,vector& color,vector adj[],int v)

{

for(int u:adj[v])

{

    if(visited[u]==false)
    {
        visited[u]=true;
        color[u]=!color[v];
        if(!isb(visited,color,adj,u))
        {
            return false;
        }
    }
    else if(color[u]==color[v])
    {
        return false;
    }
}
return true;

}

vector adj[1000005]; vector visited(2005); vector color(2005);

int main() { ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); srand(chrono::high_resolution_clock::now().time_since_epoch().count());

int t,b,in,x,y;

cin >> t;

for(int j=1;j<=t;j++) { cin>>b>>in; visited.clear(); color.clear(); for(auto& vec: adj){vec.clear();} for(int i=0;i<in;i++) { cin>>x>>y; adj[x].push_back(y); adj[y].push_back(x); } visited[1]=true; color[1]=0; if(isb(visited,color,adj,1)) { cout<<"Scenario #"<<j<<":"<<endl; cout<<"No suspicious bugs found!"<<endl; } else { cout<<"Scenario #"<<j<<":"<<endl; cout<<"Suspicious bugs found!"<<endl; } }

return 0; }

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en4 English optimus2409 2020-10-06 21:57:52 20
en3 English optimus2409 2020-10-06 21:56:03 10
en2 English optimus2409 2020-10-06 21:54:29 2
en1 English optimus2409 2020-10-06 21:52:14 1312 Initial revision (published)