optimus2409's blog

By optimus2409, history, 4 years ago, In English
#include <bits/stdc++.h>
using namespace std;

bool isb(vector<bool>& visited,vector<bool>& color,vector<int> 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<int> adj[1000005];
  vector<bool> visited(2005);
 vector<bool> 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;
}
  • Vote: I like it
  • -3
  • Vote: I do not like it

| Write comment?