iamyeasin

Untitled

Mar 20th, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.55 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. #define pf printf
  3. #define sf scanf
  4. #define none 0
  5. #define white 1
  6. #define black 2
  7. #define DBG cout << "DEBUG " << endl;
  8.  
  9. using namespace std;
  10.  
  11. long n,m,edges;
  12.  
  13. vector < int > adjList[1234];
  14. bitset < 1234 > visited;
  15.  
  16. int dx[] = {  2, 1, -1, -2,  -2, -1,  1,  2  };
  17. int dy[] = {  1, 2,  2,  1,  -1, -2, -2, -1  };
  18.  
  19. int color[12345];
  20. bool pass = true;
  21.  
  22. void dfs( int p, int c, int clr ){
  23.  
  24.     if(color[p] == clr && visited[p]) {
  25.         pass = false;
  26.         return;
  27.     }
  28.  
  29.     color[p] = clr;
  30.  
  31.     for( auto x : adjList[p] ){
  32.         if( x != c && !visited[x] ){
  33.             visited[x] = 1;
  34.             dfs( x, p ,clr^1);
  35.         }
  36.     }
  37. }
  38.  
  39. void print(){
  40.     for( int i=1; i<=edges; i++ ){
  41.         int sz = adjList[i].size();
  42.         cout << i << " -> " ;
  43.         for( int j=0; j<sz; j++ ){
  44.             cout << adjList[i][j] << " ";
  45.         }
  46.         cout << endl;
  47.     }
  48. }
  49.  
  50.  
  51. int main(){
  52.     #ifndef ONLINE_JUDGE
  53.         freopen("input.txt","rt",stdin);
  54. //    freopen("out.txt","wt",stdout);
  55.     #endif
  56.  
  57.     memset( color , -1 , sizeof color );
  58.  
  59.     cin >> edges;
  60.  
  61.     for( int i=1; i<=edges; i++ ){
  62.         int x,y;
  63.         cin >> x >> y;
  64.         adjList[x].push_back( y );
  65.         adjList[y].push_back( x );
  66.     }
  67.  
  68.     dfs( 1, -1, 0);
  69.     puts("");
  70.  
  71.     for( int i=1; i<=7; i++ ) cout << i << " " << color[i] << endl;
  72.     puts("");
  73.  
  74.  
  75.     if(pass)
  76.         cout << "The Graph is BI-COLORABLE" << endl;
  77.     else
  78.         cout << "The Graph is not BI-COLORABLE" << endl;
  79.  
  80.  
  81.     return 0;
  82. }
Add Comment
Please, Sign In to add comment