Advertisement
Guest User

Untitled

a guest
Jul 9th, 2019
374
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.50 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int N = 1e5+10; // just a constant for the maximum number of nodes
  6. vector <int> adj[N]; // adjacency list
  7. bool ok = 1; // this indicates if exists a 0-1 coloring for this graph
  8. int c[N]; // c[i] -> color of vertex i
  9.  
  10. void dfs(int v, int c){
  11.   for(auto &u : adj[v]){
  12.     if (c[u]==-1) dfs(u, !c);
  13.     else if (c[u]==c[v]){
  14.       ok = 0;
  15.       return;
  16.     }
  17.   }
  18. }
  19.  
  20. int main(){
  21.   // read the graph
  22.   memset(c, -1, sizeof c);
  23.   dfs(1, 0);
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement