Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- const int N = 1e5+10; // just a constant for the maximum number of nodes
- vector <int> adj[N]; // adjacency list
- bool ok = 1; // this indicates if exists a 0-1 coloring for this graph
- int c[N]; // c[i] -> color of vertex i
- void dfs(int v, int c){
- for(auto &u : adj[v]){
- if (c[u]==-1) dfs(u, !c);
- else if (c[u]==c[v]){
- ok = 0;
- return;
- }
- }
- }
- int main(){
- // read the graph
- memset(c, -1, sizeof c);
- dfs(1, 0);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement