提交时间:2024-01-03 13:30:43
运行 ID: 119028
#include<bits/stdc++.h> using namespace std; const int MXN = 100005; int fa[MXN << 1], N, M, anssize; char ans[MXN]; int find(int x){ return x ^ fa[x] ? fa[x] = find(fa[x]) : x; } int main() { scanf("%d%d", &N, &M); for(int i(0); i != N * 2; ++i) fa[i] = i; for(int t(0), x(0), y(0); M--;){ scanf("%d%d%d", &t, &x, &y); --x, --y; if(t == 1){ fa[find(x)] = find(y); fa[find(x + N)] = find(y + N); if(find(x) == find(x + N)){ puts("ORZKsister"); return 0; } } if(t == 2){ fa[find(x)] = find(y + N); fa[find(x + N)] = find(y); if(find(x) == find(x + N)){ puts("ORZKsister"); return 0; } } if(t == 3){ if(find(x) == find(y))ans[anssize++] = 'Z'; else if(find(x) == find(y + N))ans[anssize++] = 'J'; else ans[anssize++] = 'K'; } } for(int i(0); i != anssize; ++i) putchar(ans[i]), putchar(10); return 0; }