位运算很强大啊
这个题解中文讲解很详细,个人感觉代码上稍微有点繁琐,但总体很容易看懂
其他几个题解,代码看一眼,先来十几个define,,,GG
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
const int N=23333,T=N-10;
int n,Q,op,p,q,va,k,ans,cas=1;
int home[N],v[N],a[20],vis[N];
bool ok;
int FIND(int x){
if (home[x]==x)return x;
int kk=home[x];
home[x]=FIND(home[x]);
v[x]^=v[kk];
return home[x];
}
bool check(int i,int j,int va){
int r1=FIND(i),r2=FIND(j);
if (r1==r2)return (v[i]^v[j])==va;
if (r1==T ) swap(r1,r2);
home[r1] = r2;
v[r1]=v[i]^v[j]^va;
return 1;
}
int main(){
//freopen("fuck.in","r",stdin);
for (;scanf("%d%d",&n,&Q)==2;cas++){
if (n==0&&Q==0)break;
printf("Case %d:
",cas);
for (int i=0;i<=n+1;i++)home[i]=i;
memset(v,0,sizeof(v));
home[T]=T;
ok=1; op=0;
for (int time=0;time<Q;time++){
char ch[2]; scanf("%s",ch);
if (ch[0]=='I') {
char st[55]; gets(st); op++;
if (sscanf(st,"%d%d%d",&p,&q,&va)==2)
{ va = q ; q = T ; }
if (!ok)continue;
if (!check(p,q,va)){
ok=0;
printf("The first %d facts are conflicting.
",op);
}
}
else {
ans=0; scanf("%d",&k);
memset(vis,0,sizeof(vis));
for (int i=0;i<k;i++){
scanf("%d",&a[i]);
if (!ok)continue;
int root=FIND(a[i]);
ans^=v[a[i]];
a[i]=root;
vis[root]^=1;
}
if (!ok)continue;
bool okk=1;
for (int i=0;i<k;i++)
if (vis[a[i]]&&a[i]!=T)okk=0;
if (okk)printf("%d
",ans);
else puts("I don't know.");
}
}
puts("");
}
return 0;
}
hust抽风了一下
最后是这样
两发WA是因为从pdf里面复制 I don’t know 的时候
粘到txt里面就变成了I don‘t know,坑爹啊