can any one tell what the mistake i have done ??
question is bug’s life .i have used dfs method
this is my solution
#include <bits/stdc++.h>
using namespace std;
vector g[2001];
int vis[2001],col[2001];
bool dfs(int node,int c){
vis[node]=1;
col[node]=c;
for(int child:g[node]){
if(vis[child]==0){
bool res=dfs(child,c^1);
if(res==false)
return false;
}
else{
if(col[node]==col[child])
return false;
}
}
return true;
}
int main(){
int n,k,a,b,t;
cin>>t;
for(int tc=1;tc<=t;tc++){
cin>>n>>k;
for(int i=1;i<=n;i++){
g[i].clear();
vis[i]=0;col[i]=0;
}
for(int i=1;i<=k;i++)
{
cin>>a>>b;
g[a].push_back(b);
g[b].push_back(a);
}
bool flag=true;
for(int i=1;i<=n;i++){
if(vis[i]==0){
int res=dfs(i,0);
if(res==false)
flag=false;
}
}
cout<<“Scenario #”<<tc<<":"<<endl;
if (flag==false)
cout<<“Suspicious bugs found!”<<endl;
else
cout<<“NO suspicious bugs found!”<<endl;
}
return 0;
}