Don't want to adjust the problem again ... I would have done that, but it was a hole in my reading. Is the pit .... Yes, it's really a hole this time.
Can not waste too much time on the problem, neither obviously improve the code ability, but can not improve the thinking, also can not learn knowledge points.
I can only say that the question of why the psychological so gloomy, out of such a problem and revenge on the community what is the difference ...
#include <iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<algorithm>#include<vector>#defineREP (I,A,B) for (int i=a;i<=b;i++)#defineMS0 (a) memset (A,0,sizeof (a))using namespaceStd;typedefLong Longll;Const intmaxn=1000100;Const intinf=1e9+Ten;intn,m;Charop[Ten];intp,q,v;intk,pk[ +];vector<int> d[ +];intDN;intFA[MAXN],W[MAXN],VAL[MAXN];intFlag;intRK;intSZ[MAXN];voidInit () {REP (I,0,2) fa[i]=i,w[i]=0, val[i]=-1, sz[i]=1; REP (i,0, -) D[i].clear ();}intFindintx) { if(fa[x]==x)returnx; intt=find (fa[x]); W[t]=0; W[X]^=W[fa[x]]; returnfa[x]=t;}voidUnion (intPintQintv) { if(flag==0)return; intX=find (p), y=find (q); if(x==y) { if((W[p]^w[q])!=v) flag=0; } Else{ if(sz[x]>Sz[y]) swap (x, y), swap (P,Q); if(~val[x]&&~Val[y]) { if((W[p]^val[x]^w[q]^val[y])!=v) flag=0; Else{fa[x]=y; Sz[y]+=Sz[x]; SZ[X]=0; W[X]= (w[p]^w[q]^v); W[y]=0; } } Else{fa[x]=y; W[X]= (w[p]^w[q]^v); W[y]=0; if(val[y]==-1){ if(~val[x]) val[y]= (val[x]^w[x]); } } } if(flag==0) printf ("The first %d facts is conflicting.\n", RK);}voidChangeintPintv) { if(flag==0)return; intx=find (P); if(~Val[x]) { if((W[p]^val[x])!=v) flag=0; } ElseVal[x]= (v^w[p]); if(flag==0) printf ("The first %d facts is conflicting.\n", RK);}BOOLcmpintAintb) { returnfa[a]<fa[b];}intquery () {REP (I,1, K) d[i].clear (); intres=0; Sort (PK+1, pk+k+1, CMP); DN=1; d[1].push_back (pk[1]); intpx=fa[pk[1]]; REP (i,2, K) { if(fa[pk[i]]==px) d[dn].push_back (pk[i]); Else{ ++DN; PX=Fa[pk[i]]; D[dn].push_back (Pk[i]); }} REP (I,1, DN) { if((int) d[i].size ()%2==0){ for(intj=0; J<d[i].size (); j + +) res^=W[d[i][j]]; } Else{ intx=fa[d[i][0]]; if(val[x]==-1)return-1; for(intj=0; J<d[i].size (); j + +) res^= (val[x]^W[d[i][j]]); } } returnRes;}voidsolve () {flag=1; rk=0; REP (i,1, M) {scanf ("%s", op); if(op[0]=='I'){ ++RK; Gets (OP); if(Sscanf (OP,"%d%d%d", &p,&q,&v) = =3) Union (P,Q,V); ElseChange (P,Q); } Else{scanf ("%d",&k); REP (i,1, K) {scanf ("%d",&Pk[i]); Find (Pk[i]); } if(flag==0)Continue; LL TMP=query (); if(tmp==-1) printf ("I don ' t know.\n"); Elseprintf"%d\n", TMP); } }}intMain () {Freopen ("In.txt","R", stdin); intcasen=1; while(~SCANF ("%d%d",&n,&m)) { if(n==0&&m==0) Break; printf ("Case %d:\n", casen++); Init (); Solve (); Puts (""); } return 0;}/**6 5I 1 2 1I 3 4 2I 4 5 3Q 2 3 5Q 4 1 2 3 6I 0 1 3Q 1 0Q 2 1 0I 0 2Q 1 1Q 1 0 3I 1 0 6I 2 2 2Q 1 0 1I 0 1 8Q 2 0 0*/
View Code
hdu3234 exclusive-or take right and check set