提交时间:2022-08-01 11:56:23

运行 ID: 54371

#include<bits/stdc++.h> using namespace std; int n,m,op,a,b,f[200005]; int gefa(int x){ return f[x]^x?f[x]=gefa(f[x]):x; } inline void Merge(int x,int y){ if(x^y) f[x]=y; } int main(){ scanf("%d%d",&n,&m); for(int i(1);i<=(n<<1);++i) f[i]=i; for(int i(1);i<=m;++i){ scanf("%d%d%d",&op,&a,&b); if(op==1){ Merge(gefa(a),gefa(b)); Merge(gefa(a+n),gefa(b+n)); } else if(op==2){ Merge(gefa(a),gefa(b+n)); Merge(gefa(a+n),gefa(b)); } else{ if(a==b) puts("Z"); else{ int fa(gefa(a)),fb(gefa(b)),fan(gefa(a+n)),fbn(gefa(b+n)); if(fa==fan||fb==fbn) puts("ORZKsister"); else if(fa==fb&&fan==fbn) puts("Z"); else if(fa==fbn&&fb==fan) puts("J"); else puts("K"); } } } return 0; }