1 #include"bits/stdc++.h"
2 using namespace std;
3 #define I inline
4 #define ls ch[x][0]
5 #define rs ch[x][1]
6 #define R register
7 const int N = 300010;
8
9
10 int ch[N][2],fa[N],r[N];
11
12 template <typename _tp> inline _tp in(_tp&x)
13
26 I void pushup(R int x) {}
27 I void pushr(R int x)
28 {
29 swap(ls,rs);
30 r[x]^=1;
31 }
32 I void pushdown(R int x)
33
42 }
43 I int nroot(R int x)
44 {
45 return ch[fa[x]][0]==x||ch[fa[x]][1]==x;
46 }
47 I void downall(R int x)
48
53 I void rot(R int x)
54
66 I void splay(R int x)
67
76 pushup(x);
77 }
78 I void access(R int x)
79 {
80 for(int y=0; x; y=x,x=fa[x])
81 splay(x),rs=y,pushup(x);
82 }
83 I int makeroot(R int x)
84 {
85 access(x);
86 splay(x);
87 pushr(x);
88 }
89 I int findroot(R int x)
90 {
91 access(x);
92 splay(x);
93 while(ls)
94 pushdown(x),x=ls;
95 splay(x);
96 return x;
97 }
98 I void link(R int x,R int y)
99
104 I void cut(R int x,R int y)
105
112 }
113 int va[N],vb[N];
114 int p;
115 int n,m;
116
117 int main()
118 {
119
120
121 in(n),in(m);
122 for(int i=1; i<n; i++)
123 {
124 int l,r;
125 in(l),in(r);
126 link(l,r);
127 }
128 while(m--)
129
139 else if(s=='C')
140 {
141 int l,r;
142 in(l),in(r);
143 cut(l,r);
144 va[++p]=l,vb[p]=r;
145 }
146 else
147 {
148 int k;
149 in(k);
150 link(va[k],vb[k]);
151 }
152 }
153 }
PLCT检查是什么P3950 部落冲突 (LCT暴力)
未经允许不得转载:上海聚慕医疗器械有限公司 » PLCT检查是什么P3950 部落冲突 (LCT暴力)












