#include #include #include #include #include #include #include #include #include #include #include #include #include #include #pragma warning(disable:4996) typedef long long ll; #define MIN(a, b) ((a)>(b)? (b): (a)) #define MAX(a, b) ((a)<(b)? (b): (a)) #define LINF 9223300000000000000 #define INF 2140000000 const long long MOD = 1000000007; //const long long MOD = 998244353; using namespace std; vector > > g; // to, directed edge vector visedge; // visit flag for directed edge bool dfs(int paredge, int curr) { auto it=g[curr].begin(); while(it!=g[curr].end()) { int next=it->first; int edge=it->second; if(edge/2==paredge/2) { ++it; continue; } if(visedge[edge]) { return true; } visedge[edge]=1; if (dfs(edge, next)) { return true; } it++; g[curr].erase(make_pair(next,edge)); } return false; } void solve(int n, int m, const vector& a, const vector& b, const vector c) { g.resize(n); visedge.resize(m*2); int i; for(i=0; i=2); assert(m>=1); assert(m<=200000); vector a(m),b(m),c(m); int i; set,int> > ss; for(i=0; i=1 && a[i]<=n); assert(b[i]>=1 && b[i]<=n); assert(c[i]==1 || c[i]==2); assert(a[i]!=b[i]); if(c[i]==1) { assert(a[i]