http://www.lydsy.com/JudgeOnline/problem.php?id=1202
S[i]=a[1]+a[2]+...+a[i], i.e. s[i] is prefixed and. Again make V[i]=s[f[i]]-s[i], where F[i] is the father of I. For each x,y,k read, x, Y is treated as a node, if X is the same as the root node of y, because V[y]-v[x]=s[f[y]]-s[y]-s[f[x]]-s[x] and f[y]=f[x], so v[y]-v[x] is the and of the interval [x, y]. So only need to judge V[y]-v[x] is equal to K on it. If x is not the same as the root node of Y, merge two nodes and update the information.
#include <cstdio>#include<cstring>using namespacestd;intn,i,j,m,f[101],w,x,y,k,v[101];BOOLFlag;intFindintx) { if(X==f[x])returnx; inttmp=F[x]; Record the original father F[x]=find (f[x]); V[X]+=V[tmp]; Update node Informationreturnf[x];}BOOLUnion1 (intXintYintk) { intFx=find (x), fy=find (y); if(fx==FY) { if(v[y]-v[x]!=k)return 0; }Else{F[fy]=x; V[FY]=k-v[y]+V[x]; Update node Information}return 1;}intMain () {scanf ("%d",&W); while(w--) {memset (V,0,sizeof(v)); Flag=0; scanf ("%d%d",&n,&m); for(i=0; i<=n;i++) f[i]=i; for(i=1; i<=m;i++) {scanf ("%d%d%d",&x,&y,&k); if(!flag&&!union1 (x1, y,k)) flag=1; } if(flag) printf ("false\n");Elseprintf"true\n"); } return 0;}
bzoj1202--with right and check set + prefix and