fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define int long long
  4. #define dd double
  5. #define ld long double
  6. #define ull unsigned long long
  7. #define yes cout << "YES\n"
  8. #define no cout << "NO\n"
  9. #define el "\n"
  10. #define Arwa ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  11. #define fix(x) cout << fixed << setprecision(x)
  12. #define all(v) v.begin(),v.end()
  13. #define dpp(v,val) memset(v,val,sizeof(v))
  14. #define mod 1e9+7
  15. #define N 100005
  16. int n;
  17. int vis[N];
  18. vector<int>adj[N];
  19. bool valid=true;
  20. vector<int>ans;
  21. void dfs_rec(int node,int type)
  22. {
  23. vis[node]=type;
  24. for(int i=0;i<adj[node].size();i++)
  25. {
  26. int ch=adj[node][i];
  27. if(vis[ch])
  28. {
  29. if(vis[ch]==type)
  30. valid=0;
  31. continue;
  32. }
  33. dfs_rec(ch,3-type);
  34. }
  35. }
  36.  
  37. void HereWeGoAgain()
  38. {
  39. int m; cin>>m;
  40. for(int i=0;i<=N;i++)
  41. vis[i]=0, adj[i].clear();
  42. for(int i=0;i<m;i++)
  43. {
  44. int x,y; cin>>x>>y;
  45. adj[x+1].push_back(y+1);
  46. adj[y+1].push_back(x+1);
  47. }
  48. valid=1;
  49. for(int i=1;i<=n;i++)
  50. {
  51. if(!vis[i]) dfs_rec(i,1);
  52. }
  53. if(valid)
  54. cout<<"BICOLORABLE."<<el;
  55. else
  56. cout<<"NOT BICOLORABLE."<<el;
  57. }
  58. int32_t main()
  59. {
  60. Arwa
  61. int t=1;
  62. //cin>>t;
  63. //for(int i=1;i<=t;i++)
  64. cin>>n;
  65. while(n!=0)
  66. {
  67. HereWeGoAgain();
  68. cin>>n;
  69. }
  70. return 0;
  71. }
  72.  
Success #stdin #stdout 0.01s 5728KB
stdin
Standard input is empty
stdout
Standard output is empty