#include <vector>
#include <iostream>
using namespace std;
int n,l;
vector<vector<int> > rel;
vector<int> vis;
int dfs(int i,int col){
if(vis[i]==(1-col))
return 0;
if(vis[i]==col)
return 1;
vis[i]=col;
int flag=1;
for(int j=0;j<rel[i].size();j++){
flag&=dfs(rel[i][j],1-col);
}
return flag;
}
int main(){
while(cin>>n){
if(!n)
return 0;
vis.assign(n,-1);
rel.assign(n,vector<int>());
cin>>l;
for(int i=0;i<l;i++){
int x,y;
cin>>x>>y;
rel[x].push_back(y),rel[y].push_back(x);
}
if(!dfs(0,0))
cout<<"NOT ";
cout<<"BICOLORABLE."<<endl;
}
}
#include <iostream>
using namespace std;
int n,l;
vector<vector<int> > rel;
vector<int> vis;
int dfs(int i,int col){
if(vis[i]==(1-col))
return 0;
if(vis[i]==col)
return 1;
vis[i]=col;
int flag=1;
for(int j=0;j<rel[i].size();j++){
flag&=dfs(rel[i][j],1-col);
}
return flag;
}
int main(){
while(cin>>n){
if(!n)
return 0;
vis.assign(n,-1);
rel.assign(n,vector<int>());
cin>>l;
for(int i=0;i<l;i++){
int x,y;
cin>>x>>y;
rel[x].push_back(y),rel[y].push_back(x);
}
if(!dfs(0,0))
cout<<"NOT ";
cout<<"BICOLORABLE."<<endl;
}
}
Comments
Post a Comment