Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- bool DFScheck(int G[][MAX], int source, int c, vector<int>&color,int V){
- if(color[source]!=-1&&color[source]==1-c)
- return false;
- bool ans=true;
- color[source]=c;
- for(int i=0;i<V;i++){
- if(G[source][source])
- return false;
- if(G[source][i]&&color[i]==-1){
- ans&=DFScheck(G,i,1-c,color,V);
- }
- else if(G[source][i]&&color[i]==c)
- return false;
- if(!ans)
- return false;
- }
- // cout<<ans<<endl;
- return ans;
- }
- bool isBipartite(int G[][MAX],int V)
- {
- vector<int>color(V,-1);
- bool ans=true;
- // ans=;
- for(int i=0;i<V;i++){
- if(color[i]==-1){
- ans=ans&DFScheck(G,0,0,color,V);
- }
- }
- return ans;
- }
Add Comment
Please, Sign In to add comment