Solution:
A better graph theory problem.
To do this, first of all to analyze love relationship and hate relationship, love relationship is transitive. More crucially, the hate relationship is not a singular ring.
It is natural to see the characteristics of the binary diagram without the odd ring.
Then the current task is to dye the first two points, to determine whether a given edge is conflicting, and to indent.
Let's assume that the next point in the graph is the K-point. The hate relationship of this K-point satisfies the relationship of the binary graph.
Then calculate the number of combinations, the total 2^ (k-1) method.
#include <bits/stdc++.h>using namespacestd;Const intN =100009; typedef pair<int,int>II;intVis[n], N, M, Flag, S;vector<ii>E[n];voidDFS (intXintk) {Vis[x]=K; --s; for(Auto &I:e[x]) { if(!~Vis[i.first]) {DFS (I.first, K^I.second); } Else { if((Vis[x]^vis[i.first])! =i.second) {flag=1; return ; } } if(flag)return; }}intMain () {memset (Vis,-1,sizeofvis); Ios::sync_with_stdio (0 ); CIN>> N >>m; S=N; for(inti =1, u, V, c; I <= m; ++i) {cin>> u >> v >>C; E[u].push_back (Make_pair (V, c^1) ); E[v].push_back (Make_pair (U, c^1) ); } for(inti =1; I <= N; ++i) {if(!~vis[i] &&!E[i].empty ()) { ++s; DFS (i,1); } if(flag) {cout<<0<<Endl; return 0; } } Long LongAns =1, p =2; --s; while(S >0 ) { if(S &1) ans = ans * p%1000000007; P= (p * p)%1000000007; S>>=1; } cout<< ans <<Endl;}View Code
Codeforces 553C Love triangles (graph theory)