1#include <cstdio>2#include <cstdlib>3#include <cstring>4 5#include <string>6#include <vector>7#include <Set>8#include <map>9#include <queue>Ten#include <math.h> One A#include <algorithm> -#include <iostream> - the Const intINF =0x7f7f7f7f; - Const intMOD =1000000007; - using namespacestd; -typedefLong Longll; + -vector<pair<int,int> > vec[100005]; + intvis[100005]; A ll ans; at - voidDfsintu) { - for(inti =0; I < vec[u].size (); i + +){ - intv=Vec[u][i].first; - intp =Vec[u][i].second; - if(Vis[v] = =-1){ in if(p = =1){ -VIS[V] =Vis[u]; to}Else{ +VIS[V] =!Vis[u]; - } the Dfs (v); * } $ if(p = =0&& Vis[u] = = Vis[v]) ans =0;Panax Notoginseng if(p = =1&& Vis[u]! = Vis[v]) ans =0; - } the } + A intMain () { the + intn,m; - while(SCANF ("%d%d", &n,&m)! =EOF) { $ for(inti =0; I <= N; i + +) vec[i].clear (); $ for(inti =0; I < m; i + +){ - intU,v,r; -scanf"%d%d%d",&u,&v,&R); the Vec[u].push_back (Make_pair (v,r)); - Vec[v].push_back (Make_pair (u,r));Wuyi } the - for(inti =0; I <= N; i + +) vis[i] =-1; Wu -Ans = (mod+1)/2; About for(inti =1; I <= N; i + +){ $ if(Vis[i] = =-1){ -Vis[i] =0; -Ans = (ans*2)%MOD; - DFS (i); A } + } thecout << ans <<Endl; - } $ return 0; the}
CF Round #309 (Div. 2) E-love triangles (two-figure dyeing)