说好卡dfs的。。本来还想在选根上动下手脚,看来不用辣23333

身为蒟蒻怎么可能会博弈论,度娘告诉我们只需要判断异或和==0就行了

然后链剖+BIT就可以了(用BIT后链剖头一次这么短,不过我没感觉到就是了,BIT大法吼啊

貌似dfs序也能做,太弱了还不会。。

 1 #include<bits/stdc++.h>
 2 #define inc(i,l,r) for(int i=l;i<=r;i++)
 3 #define dec(i,l,r) for(int i=l;i>=r;i--)
 4 #define link(x) for(edge *j=h[x];j;j=j->next)
 5 #define mem(a) memset(a,0,sizeof(a))
 6 #define inf 1e9
 7 #define ll long long
 8 #define succ(x) (1<<x)
 9 #define lowbit(x) (x&(-x))
10 #define NM 500000+5
11 using namespace std;
12 int read(){
13     int x=0,f=1;char ch=getchar();
14     while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
15     while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
16     return x*f;
17 }
18 struct edge{
19     int t;
20     edge *next;
21 }e[2*NM],*h[NM],*o=e;
22 void add(int x,int y){
23     o->t=y;o->next=h[x];h[x]=o++;
24 }
25 int n,d[NM],f[NM],id[NM],top[NM],TOP,son[NM],size[NM],tot;
26 int _x,_y,a[NM],b[NM],c[NM];
27 void dfs1(int x){
28     link(x)if(!f[j->t]){
29         f[j->t]=x;d[j->t]=d[x]+1;
30         dfs1(j->t);
31         size[x]+=size[j->t];
32         if(size[j->t]>size[son[x]])son[x]=j->t;
33     }
34     size[x]++;
35 }
36 void dfs2(int x){
37     top[x]=TOP;id[x]=++tot;
38     if(son[x])dfs2(son[x]);
39     link(x)if(!top[j->t])dfs2(TOP=j->t);
40 }
41 void upd(int x,int t){
42     for(;x<=n;x+=lowbit(x))a[x]^=t;
43 }
44 int sum(int x){
45     int s=0;
46     for(;x;x-=lowbit(x))s^=a[x];
47     return s;
48 }
49 void query(int x,int y){
50     int s=0;
51     for(;top[x]!=top[y];x=f[top[x]]){
52         if(d[top[x]]<d[top[y]])swap(x,y);
53         s^=sum(id[x])^sum(id[top[x]]-1);
54     }
55     if(d[x]<d[y])swap(x,y);
56     s^=sum(id[x])^sum(id[y]-1);
57     puts(s?"Yes":"No");
58 }
59 int main(){
60     freopen("data.in","r",stdin);
61     n=read();
62     inc(i,1,n)c[i]=read();
63     inc(i,1,n-1){
64         _x=read();_y=read();add(_x,_y);add(_y,_x);
65     }
66     f[1]=1;dfs1(1);dfs2(TOP=1);
67     inc(i,1,n)upd(id[i],c[i]),b[id[i]]=c[i];
68     int m=read();
69     while(m--){
70         char st[10];scanf("%s",st);_x=read();_y=read();
71         if(st[0]=='Q')query(_x,_y);
72         else upd(id[_x],b[id[_x]]^_y),b[id[_x]]=_y;
73 //        inc(i,1,n)printf("%d ",b[i]);putchar('\n');
74 //        inc(i,1,n)printf("%d ",a[i]);putchar('\n');
75     }
76     return 0;
77 }
View Code

 

posted on 2016-03-17 21:32  onlyRP  阅读(174)  评论(0编辑  收藏  举报