Preprocessing each point to the root node of the soil, inserted into a tree array, and then each modification will only affect the nodes in the subtree, thus equivalent to the interval modification, point query.
#include <cstdio>using namespace std; #define N 250001int n,en,v[n<<1],next[n<<1],first[n],m;void Addedge (const int &u,const int &v) {v[++en]=v;next[en]=first[u];first[u]=en;} int now,ls[n],rs[n],fa[n],a[n];void dfs (int U) {ls[u]=++now;for (int i=first[u];i;i=next[i]) if (V[i]!=fa[u]) {fa[v [I]] =u; a[v[i]]=a[u]+1; DFS (V[i]); }rs[u]=now;} int d[n];void add_node (int p,const int &v) {for (;p <=n;p+= (-P)) p&;} void Add_range (const int &L,CONST int &r,const int &v) {Add_node (l,v), if (r!=n) Add_node (r+1,-v);} int query (int p) {int res=0;for (;p; p-= (-P)) Res+=d[p];return res;} int main () {int A, B, Char op[2];scanf ("%d", &n), for (int i=1;i<n;++i) {scanf ("%d%d", &a,&b); Addedge (A, b); Addedge (B,a); }dfs (1), for (int i=2;i<=n;++i) Add_range (Ls[i],ls[i],a[i]), scanf ("%d", &m), and for (int i=1;i<n+m;++i) {scanf (" %s%d ", op,&a); if (op[0]== ' W ') printf ("%d\n", Query (Ls[a])); else {scanf ("%d", &b); IF (fa[a]==b) Add_range (ls[a],rs[a],-1); else Add_range (ls[b],rs[b],-1); }}return 0;}
Dfs sequence "tree array" bzoj1103 [POI2007] Metropolitan Meg