#include<bits/stdc++.h>
using namespace std;
int main()
{
int i,j,k,l,m,n,x,y,test;
while(cin>>test)
{
queue<int>q;
int color[1000];
vector<int>nodes[1000];
if(test==0)
break;
else
{
bool flag=true;
cin>>n;
for(i=0;i<n;i++)
{
cin>>x>>y;
nodes[x].push_back(y);
nodes[y].push_back(x);
}
memset(color,-1,sizeof(color));
color[0]=0;
q.push(0);
while(!q.empty())
{
x=q.front();
q.pop();
l=nodes[x].size();
for(i=0;i<l;i++)
{
if(color[nodes[x][i]]==-1)
{
if(color[x]==0)
{
color[nodes[x][i]]=1;
}
else
{
color[nodes[x][i]]=0;
}
q.push(nodes[x][i]);
}
else
{
if(color[nodes[x][i]]==color[x])
{
flag=false;
break;
}
}
}
if(flag==false)
break;
}
if(flag)
cout<<"BICOLORABLE."<<endl;
else
cout<<"NOT BICOLORABLE."<<endl;
}
}
return 0;
}
using namespace std;
int main()
{
int i,j,k,l,m,n,x,y,test;
while(cin>>test)
{
queue<int>q;
int color[1000];
vector<int>nodes[1000];
if(test==0)
break;
else
{
bool flag=true;
cin>>n;
for(i=0;i<n;i++)
{
cin>>x>>y;
nodes[x].push_back(y);
nodes[y].push_back(x);
}
memset(color,-1,sizeof(color));
color[0]=0;
q.push(0);
while(!q.empty())
{
x=q.front();
q.pop();
l=nodes[x].size();
for(i=0;i<l;i++)
{
if(color[nodes[x][i]]==-1)
{
if(color[x]==0)
{
color[nodes[x][i]]=1;
}
else
{
color[nodes[x][i]]=0;
}
q.push(nodes[x][i]);
}
else
{
if(color[nodes[x][i]]==color[x])
{
flag=false;
break;
}
}
}
if(flag==false)
break;
}
if(flag)
cout<<"BICOLORABLE."<<endl;
else
cout<<"NOT BICOLORABLE."<<endl;
}
}
return 0;
}
No comments:
Post a Comment