#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>
#define piii tuple<int, int, int>
#define F first
#define S second
using namespace std;
int N, K, pre[120005][20], ts;
pii io[120005], bin[120005][20], e[120005];
piii Q[120005];
vector<pii> E[120005];
const pii no = {-1, -1}, bad = {-2, -2};
pii merge(pii p, pii q)
{
if (p == no)
return q;
if (q == no)
return p;
if (p == bad || q == bad)
return bad;
if (p.F <= p.S && p.S <= q.F && q.F <= q.S)
return pii(p.F, q.S);
if (p.F >= p.S && p.S >= q.F && q.F >= q.S)
return pii(p.F, q.S);
return bad;
}
void dfs(int u)
{
io[u].F = ++ts;
for (auto [v, w] : E[u])
if (v != pre[u][0])
{
pre[v][0] = u;
bin[v][0] = pii(w, w);
for (int p = 0; p + 1 < 20; p++)
pre[v][p + 1] = pre[pre[v][p]][p],
bin[v][p + 1] = merge(bin[v][p], bin[pre[v][p]][p]);
dfs(v);
}
io[u].S = ts;
}
bool ischild(int r, int c)
{
return io[r].F <= io[c].F && io[c].S <= io[r].S;
}
signed main()
{
cin >> N >> K;
for (int i = 0, j = 0; i + j < K + N - 1;)
{
char c;
int a, b = 0;
cin >> c >> a;
if (c != 'C')
cin >> b;
if (c == 'S')
{
j++;
e[j] = pii(a, b);
E[a].emplace_back(pii(b, j));
E[b].emplace_back(pii(a, j));
}
else
{
i++;
Q[i] = piii(j, a, b);
}
}
for (int p = 0; p < 20; p++)
pre[1][p] = 1, bin[1][p] = no;
dfs(1);
for (int i = 1; i <= K; i++)
{
auto [t, a, b] = Q[i];
if (b > 0)
{
int u = a, v = b;
pii l = no, r = no;
for (int p = 19; p >= 0; p--)
if (!ischild(pre[u][p], v))
l = merge(l, bin[u][p]), u = pre[u][p];
if (!ischild(u, v))
l = merge(l, bin[u][0]), u = pre[u][0];
for (int p = 19; p >= 0; p--)
if (!ischild(pre[v][p], u))
r = merge(r, bin[v][p]), v = pre[v][p];
if (!ischild(v, u))
r = merge(r, bin[v][0]), v = pre[v][0];
swap(r.F, r.S);
// cerr << merge(l, r).F << ' ' << merge(l, r).S << '\n';
l = merge(merge(pii(t, t), merge(l, r)), pii(0, 0));
cout << (l != bad ? "yes\n" : "no\n");
}
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
5812 KB |
Output is correct |
2 |
Correct |
98 ms |
7372 KB |
Output is correct |
3 |
Correct |
73 ms |
7396 KB |
Output is correct |
4 |
Correct |
86 ms |
7484 KB |
Output is correct |
5 |
Correct |
78 ms |
7604 KB |
Output is correct |
6 |
Correct |
61 ms |
7400 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
54 ms |
5812 KB |
Output is correct |
2 |
Correct |
98 ms |
7372 KB |
Output is correct |
3 |
Correct |
73 ms |
7396 KB |
Output is correct |
4 |
Correct |
86 ms |
7484 KB |
Output is correct |
5 |
Correct |
78 ms |
7604 KB |
Output is correct |
6 |
Correct |
61 ms |
7400 KB |
Output is correct |
7 |
Incorrect |
50 ms |
5700 KB |
Extra information in the output file |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
5840 KB |
Output is correct |
2 |
Correct |
216 ms |
42524 KB |
Output is correct |
3 |
Correct |
195 ms |
42488 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
60 ms |
5840 KB |
Output is correct |
2 |
Correct |
216 ms |
42524 KB |
Output is correct |
3 |
Correct |
195 ms |
42488 KB |
Output is correct |
4 |
Incorrect |
46 ms |
5720 KB |
Extra information in the output file |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5700 KB |
Output is correct |
2 |
Correct |
227 ms |
51484 KB |
Output is correct |
3 |
Correct |
218 ms |
51408 KB |
Output is correct |
4 |
Correct |
214 ms |
51324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5700 KB |
Output is correct |
2 |
Correct |
227 ms |
51484 KB |
Output is correct |
3 |
Correct |
218 ms |
51408 KB |
Output is correct |
4 |
Correct |
214 ms |
51324 KB |
Output is correct |
5 |
Incorrect |
68 ms |
5708 KB |
Extra information in the output file |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5716 KB |
Output is correct |
2 |
Correct |
232 ms |
42860 KB |
Output is correct |
3 |
Correct |
186 ms |
43380 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
51 ms |
5716 KB |
Output is correct |
2 |
Correct |
232 ms |
42860 KB |
Output is correct |
3 |
Correct |
186 ms |
43380 KB |
Output is correct |
4 |
Incorrect |
55 ms |
5660 KB |
Extra information in the output file |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
5836 KB |
Output is correct |
2 |
Correct |
209 ms |
51408 KB |
Output is correct |
3 |
Correct |
195 ms |
51396 KB |
Output is correct |
4 |
Correct |
218 ms |
51344 KB |
Output is correct |
5 |
Correct |
62 ms |
5768 KB |
Output is correct |
6 |
Correct |
219 ms |
42916 KB |
Output is correct |
7 |
Correct |
235 ms |
43396 KB |
Output is correct |
8 |
Correct |
236 ms |
43784 KB |
Output is correct |
9 |
Correct |
212 ms |
43796 KB |
Output is correct |
10 |
Correct |
241 ms |
48256 KB |
Output is correct |
11 |
Correct |
340 ms |
47568 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
63 ms |
5836 KB |
Output is correct |
2 |
Correct |
209 ms |
51408 KB |
Output is correct |
3 |
Correct |
195 ms |
51396 KB |
Output is correct |
4 |
Correct |
218 ms |
51344 KB |
Output is correct |
5 |
Correct |
62 ms |
5768 KB |
Output is correct |
6 |
Correct |
219 ms |
42916 KB |
Output is correct |
7 |
Correct |
235 ms |
43396 KB |
Output is correct |
8 |
Correct |
236 ms |
43784 KB |
Output is correct |
9 |
Correct |
212 ms |
43796 KB |
Output is correct |
10 |
Correct |
241 ms |
48256 KB |
Output is correct |
11 |
Correct |
340 ms |
47568 KB |
Output is correct |
12 |
Incorrect |
53 ms |
5676 KB |
Extra information in the output file |
13 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
5696 KB |
Output is correct |
2 |
Correct |
69 ms |
7340 KB |
Output is correct |
3 |
Correct |
61 ms |
7452 KB |
Output is correct |
4 |
Correct |
83 ms |
7576 KB |
Output is correct |
5 |
Correct |
99 ms |
7664 KB |
Output is correct |
6 |
Correct |
61 ms |
7484 KB |
Output is correct |
7 |
Correct |
47 ms |
5836 KB |
Output is correct |
8 |
Correct |
183 ms |
42544 KB |
Output is correct |
9 |
Correct |
181 ms |
42484 KB |
Output is correct |
10 |
Correct |
51 ms |
5728 KB |
Output is correct |
11 |
Correct |
286 ms |
51428 KB |
Output is correct |
12 |
Correct |
211 ms |
51476 KB |
Output is correct |
13 |
Correct |
244 ms |
51348 KB |
Output is correct |
14 |
Correct |
58 ms |
5804 KB |
Output is correct |
15 |
Correct |
215 ms |
42852 KB |
Output is correct |
16 |
Correct |
215 ms |
43372 KB |
Output is correct |
17 |
Correct |
263 ms |
43776 KB |
Output is correct |
18 |
Correct |
225 ms |
43816 KB |
Output is correct |
19 |
Correct |
263 ms |
48364 KB |
Output is correct |
20 |
Correct |
317 ms |
47604 KB |
Output is correct |
21 |
Correct |
256 ms |
43068 KB |
Output is correct |
22 |
Correct |
222 ms |
43044 KB |
Output is correct |
23 |
Correct |
228 ms |
43336 KB |
Output is correct |
24 |
Correct |
213 ms |
43420 KB |
Output is correct |
25 |
Correct |
239 ms |
45108 KB |
Output is correct |
26 |
Correct |
248 ms |
42868 KB |
Output is correct |
27 |
Correct |
201 ms |
42880 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
52 ms |
5696 KB |
Output is correct |
2 |
Correct |
69 ms |
7340 KB |
Output is correct |
3 |
Correct |
61 ms |
7452 KB |
Output is correct |
4 |
Correct |
83 ms |
7576 KB |
Output is correct |
5 |
Correct |
99 ms |
7664 KB |
Output is correct |
6 |
Correct |
61 ms |
7484 KB |
Output is correct |
7 |
Correct |
47 ms |
5836 KB |
Output is correct |
8 |
Correct |
183 ms |
42544 KB |
Output is correct |
9 |
Correct |
181 ms |
42484 KB |
Output is correct |
10 |
Correct |
51 ms |
5728 KB |
Output is correct |
11 |
Correct |
286 ms |
51428 KB |
Output is correct |
12 |
Correct |
211 ms |
51476 KB |
Output is correct |
13 |
Correct |
244 ms |
51348 KB |
Output is correct |
14 |
Correct |
58 ms |
5804 KB |
Output is correct |
15 |
Correct |
215 ms |
42852 KB |
Output is correct |
16 |
Correct |
215 ms |
43372 KB |
Output is correct |
17 |
Correct |
263 ms |
43776 KB |
Output is correct |
18 |
Correct |
225 ms |
43816 KB |
Output is correct |
19 |
Correct |
263 ms |
48364 KB |
Output is correct |
20 |
Correct |
317 ms |
47604 KB |
Output is correct |
21 |
Correct |
256 ms |
43068 KB |
Output is correct |
22 |
Correct |
222 ms |
43044 KB |
Output is correct |
23 |
Correct |
228 ms |
43336 KB |
Output is correct |
24 |
Correct |
213 ms |
43420 KB |
Output is correct |
25 |
Correct |
239 ms |
45108 KB |
Output is correct |
26 |
Correct |
248 ms |
42868 KB |
Output is correct |
27 |
Correct |
201 ms |
42880 KB |
Output is correct |
28 |
Incorrect |
75 ms |
5692 KB |
Extra information in the output file |
29 |
Halted |
0 ms |
0 KB |
- |