### Link

http://acm.hdu.edu.cn/showproblem.php?pid=3234

### Problem

You are not given n non-negative integers X0, X1, …, Xn-1 less than 2 20 , but they do exist, and their values never change.

I’ll gradually provide you some facts about them, and ask you some questions.

There are two kinds of facts, plus one kind of question:

### Code

```#include <bits/stdc++.h>
using namespace std;

const int maxn = 20480;
int N, Q;
int pa[maxn], val[maxn];
char op[30];

int K, qu[30];
vector<int> rv;

void init() {
for(int i = 0; i < maxn; ++i) {
pa[i] = i;
val[i] = 0;
}
}

int Find(int x) {
if(pa[x] == x)
return x;
int rt = Find(pa[x]);
val[x] ^= val[pa[x]];
return pa[x] = rt;
}

bool Union(int x, int y, int d) {
int rx = Find(x), ry = Find(y);
if(rx == ry)
return (val[x] ^ val[y]) == d;
if(rx == N) {
swap(x, y);
swap(rx, ry);
}
pa[rx] = ry;
val[rx] = val[x] ^ val[y] ^ d;
return true;
}

int query() {
rv.clear();
for(int i = 0; i < K; ++i)
rv.push_back(Find(qu[i]));
sort(rv.begin(), rv.end());
if(rv.back() != N && rv.size() % 2)
return -1;
for(int i = 1; i < rv.size(); i += 2)
if(rv[i] != rv[i-1])
return -1;
int ans = 0;
for(int i = 0; i < K; ++i)
ans ^= val[qu[i]];
return ans;
}

int main() {
int kase = 0;
while(scanf("%d%d", &N, &Q), N || Q) {
printf("Case %d:\n", ++kase);
init();
bool ok = true;
int cnt = 0;
for(int i = 0; i < Q; ++i) {
scanf("%s", op);
if(op[0] == 'I') {
cnt += 1; gets(op);
if(!ok) continue;
int p, q, v;
if(sscanf(op, "%d%d%d", &p, &q, &v) == 2)
v = q, q = N;
if(!Union(p, q, v)) {
ok = false;
printf("The first %d facts are conflicting.\n", cnt);
}
}
else if(op[0] == 'Q') {
scanf("%d", &K);
for(int i = 0; i < K; ++i)
scanf("%d", qu + i);
if(!ok) continue;
int ans = query();
ans == -1 ? puts("I don't know.") : printf("%d\n", ans);
}
}
puts("");
}
return 0;
}
```