Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define dk23 ios_base :: sync_with_stdio(false);
- #define pb push_back
- int node,edge,n1,n2;
- vector <int> v[205];
- bool vis[205];
- int color[205];
- bool bfs()
- {
- queue <int> q;
- q.push(0);
- vis[0]=true;
- color[0]=2;
- while(!q.empty())
- {
- int x = q.front();
- q.pop();
- for(int i=0;i<v[x].size();i++){
- int y=v[x][i];
- if(!vis[y]){
- vis[y]=true;
- q.push(y);
- if(color[x]==2){
- color[y]=3;
- }
- else{
- color[y]=2;
- }
- }
- else{
- if(color[x]==color[y]){
- return false;
- }
- }
- }
- }
- return true;
- }
- int main()
- {
- dk23
- //freopen("input.txt","r",stdin);
- while(cin>>node && node!=0)
- {
- cin>>edge;
- for(int i=0;i<edge;i++) {
- cin>>n1>>n2;
- v[n1].pb(n2);
- v[n2].pb(n1);
- }
- if(bfs()){
- cout<<"BICOLORABLE."<<endl;
- }
- else {
- cout<<"NOT BICOLORABLE."<<endl;
- }
- for(int i=0;i<node;i++){
- v[i].clear();
- }
- memset(vis,0,sizeof(vis));
- memset(color,0,sizeof(color));
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment