sahadat49

Bicoloring

Mar 17th, 2020
144
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.42 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define dk23 ios_base :: sync_with_stdio(false);
  5. #define pb push_back
  6.  
  7. int node,edge,n1,n2;
  8. vector <int> v[205];
  9. bool vis[205];
  10. int color[205];
  11.  
  12. bool bfs()
  13. {
  14. queue <int> q;
  15. q.push(0);
  16. vis[0]=true;
  17. color[0]=2;
  18. while(!q.empty())
  19. {
  20. int x = q.front();
  21. q.pop();
  22. for(int i=0;i<v[x].size();i++){
  23. int y=v[x][i];
  24. if(!vis[y]){
  25. vis[y]=true;
  26. q.push(y);
  27. if(color[x]==2){
  28. color[y]=3;
  29. }
  30. else{
  31. color[y]=2;
  32. }
  33. }
  34. else{
  35. if(color[x]==color[y]){
  36. return false;
  37. }
  38. }
  39. }
  40. }
  41. return true;
  42. }
  43.  
  44.  
  45. int main()
  46. {
  47. dk23
  48.  
  49. //freopen("input.txt","r",stdin);
  50.  
  51. while(cin>>node && node!=0)
  52. {
  53. cin>>edge;
  54.  
  55. for(int i=0;i<edge;i++) {
  56. cin>>n1>>n2;
  57. v[n1].pb(n2);
  58. v[n2].pb(n1);
  59. }
  60. if(bfs()){
  61. cout<<"BICOLORABLE."<<endl;
  62. }
  63. else {
  64. cout<<"NOT BICOLORABLE."<<endl;
  65. }
  66.  
  67. for(int i=0;i<node;i++){
  68. v[i].clear();
  69. }
  70. memset(vis,0,sizeof(vis));
  71. memset(color,0,sizeof(color));
  72. }
  73. return 0;
  74. }
Advertisement
Add Comment
Please, Sign In to add comment