prakharvk

disputed

Jun 27th, 2019
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. bool DFScheck(int G[][MAX], int source, int c, vector<int>&color,int V){
  2.     if(color[source]!=-1&&color[source]==1-c)
  3.         return false;
  4.     bool ans=true;
  5.     color[source]=c;
  6.     for(int i=0;i<V;i++){
  7.         if(G[source][source])
  8.             return false;
  9.         if(G[source][i]&&color[i]==-1){
  10.             ans&=DFScheck(G,i,1-c,color,V);
  11.         }
  12.         else if(G[source][i]&&color[i]==c)
  13.             return false;
  14.         if(!ans)
  15.             return false;
  16.     }    
  17.     // cout<<ans<<endl;
  18.     return ans;
  19. }
  20. bool isBipartite(int G[][MAX],int V)
  21. {
  22.      vector<int>color(V,-1);
  23.      bool ans=true;
  24.     //  ans=;
  25.      for(int i=0;i<V;i++){
  26.          if(color[i]==-1){
  27.              ans=ans&DFScheck(G,0,0,color,V);
  28.          }
  29.      }
  30.      return ans;
  31. }
Add Comment
Please, Sign In to add comment