Orz Iwtwiioi http://www.cnblogs.com/iwtwiioi/p/3887617.htmland check the set + prefix and
Ah ... This is supposed to be a water problem, right? But I didn't even think of this big sand tea all day ... Sentence negative ring, the shortest short-circuit what have tried, are kneeling ...
"If we were able to launch according to the previous information, the R day should be much more than the first l-1 days, and then compare with this time, we know that the current message is not false." "Konjac Konjac thought.
The above query with a prefix and can be very convenient to implement ~ But the problem is each message, both equivalent to an update operation (for the case of unknown relationship), and want to be a query operation (for the known), how to separate it? Moreover, there will be a transfer between the changes, such as the beginning we know [1,3] and [6,7] these days of information, the next time we give a [4,5] information, we have to combine all the front and back ...
Wait a minute......? Merge? And check the set?
Well, it's not a differential constraint, or a 2-sat, it's a check set ...
For a "set", S[i] represents the difference in money (prefixes and oh ~) from day I to fa[i] days. For each piece of information, if L and R are in the same set, the prefix and the differential are directly used and compared to Val, if not in the same set, merge two sets. Draw your own hand to see what the situation is.
1 /**************************************************************2 problem:12023 User:programmingape4 language:c++5 result:accepted6 time:112 Ms7 memory:808 KB8 ****************************************************************/9 Ten //Bzoj 1202 One#include <cstdio> A#include <cstdlib> -#include <cstring> -#include <algorithm> the #defineRep (i,n) for (int i=0;i<n;++i) - #defineF (i,j,n) for (int i=j;i<=n;++i) - #defineD (i,j,n) for (int i=j;i>=n;--i) - #definePB Push_back + using namespacestd; - Const intn= the, inf=~0u>>2; + //#define DEBUG A voidReadint&v) { atv=0;ints=1; - CharCh=GetChar (); - while(ch<'0'|| Ch>'9'){if(ch=='-') s=-1; Ch=GetChar ();} - while(ch>='0'&& ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -v*=s; -}//Âèµ°£¬¾óè»êç¶áèë³ö´íáë in - intN,m,fa[n],s[n]; to intGetfather (intx) { + if(fa[x]==x)returnx; - Else { the intp=Fa[x]; *Fa[x]=getfather (Fa[x]);//you have to change your father before you change it. $s[x]+=S[p];Panax Notoginseng returnFa[x]; - } the } + intMain () { A //freopen ("Input.txt", "R", stdin); the intT; + read (T); - while(t--){ $ read (n); read (m); $F (I,0, N) fa[i]=i,s[i]=0; - - BOOLsign=1; the intfx,fy,x,y,z; -F (I,1, M) {WuyiRead (x), read (y), read (z); --x; theFx=getfather (x); fy=Getfather (y); - if(fx!=FY) { Wufa[fx]=fy; -S[fx]=s[y]-s[x]+z;//here is the point ... Well, think about it. About } $ Else if(s[x]-s[y]!=z) {sign=0; Break;} - } - if(sign) printf ("true\n"); - Elseprintf"false\n"); A + } the return 0; -}
View Code
"Bzoj" "1202" "HNOI2005" cunning businessman