DFS sequence
Template problem, the point +1 out Point-1, just for the point not on the path in one out just offset, because the subject to be dynamically modified (into the road after the +1-1 have become 0) so in the sequence of a tree-like array.
Tle:1. Recursive Dfs blew up ... wrote a manual stack.
2. Forget to delete Freopen ... Qaq my AC rate ah ...
1 /**************************************************************2 problem:11033 User:tunix4 language:c++5 result:accepted6 time:3884 Ms7 memory:10060 KB8 ****************************************************************/9 Ten //Bzoj 1103 One#include <cstdio> A#include <cstring> -#include <cstdlib> -#include <iostream> the#include <algorithm> - #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; + voidReadint&v) { Av=0;intsign=1;CharCh=GetChar (); at while(ch<'0'|| Ch>'9'){if(ch=='-') sign=-1; Ch=GetChar ();} - while(ch>='0'&&ch<='9') {v=v*Ten+ch-'0'; Ch=GetChar ();} -v*=Sign ; - } - #defineDebug - /******************tamplate*********************/ in Const intn=250010; - inthead[n],to[n],next[n],cnt; to voidAddintXinty) { +To[++cnt]=y; NEXT[CNT]=HEAD[X]; head[x]=CNT; - } the /********************edge**********************/ * intn,m,dfs_clock,t[n*2],l[n],r[n]; $InlineintLowbit (intx) {returnx& (-x);}Panax Notoginseng voidUpdateintXintval) { - for(inti=x;i<=n*2; i+=lowbit (i)) thet[i]+=Val; + } A intSumintx) { the inttemp=0; + //for (int i=1;i<=x;++i) temp+=t[i]; - for(intI=x;i;i-=lowbit (i)) temp+=T[i]; $ returntemp; $ } - intfa[n],st[n],top=0; - voidDfs () { thest[++top]=1; - while(top) {Wuyi intx=St[top]; the if(!L[x]) { -l[x]=++Dfs_clock; Wu for(intI=head[x];i;i=Next[i]) -st[++top]=To[i]; About } $ Else{ -r[x]=++Dfs_clock; -top--; - } A } + } the intMain () { - read (n); $ intx, y; theF (I,2, N) { the read (x); Read (y); the Add (x, y); the } - dfs (); inmemset (T,0,sizeoft); theF (I,2, n) {update (l[i],1); Update (r[i],-1);} the Charcmd[3]; About read (m); theF (I,1, n+m-1){ thescanf"%s", cmd); the if(cmd[0]=='A'){ + read (x); Read (y); -Update (l[y],-1); Update (R[y],1); the }Bayi Else{ the read (x); theprintf"%d\n", SUM (l[x])); - } - } the return 0; the}
View Code
"Bzoj" "1103" "POI2007" Metropolitan Meg