#include using namespace std; struct UnionFind{ vector parent; vector numberOfElements;//根ノードのみ有効 UnionFind(int n){ parent.resize(n); numberOfElements.resize(n); for(int i=0;i path(0); int pointer=a; while(parent[pointer]!=-1){ path.push_back(pointer); pointer=parent[pointer]; } for(int i:path){ parent[i]=pointer; } return pointer; } void unite(int a,int b){ int p=find(a); int q=find(b); if(p==q){ return; } if(numberOfElements[p]>N; map cnt; vector> a(N,vector(2)); for(int i=0;i>a[i][j]; cnt[a[i][j]]+=j*2-1; } } int p=cnt.size(); map comp; for(auto i=cnt.begin();i!=cnt.end();++i){ comp[i->first]=temp; ++temp; check+=abs(i->second); } UnionFind U(p); for(vector v:a){ U.unite(comp[v[0]],comp[v[1]]); } temp=U.find(comp[a[0][0]]); for(auto i=cnt.begin();i!=cnt.end();++i){ if(U.find(comp[i->first])!=temp){ cout<<0<2){ cout<<0<