# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
544688 |
2022-04-02T14:24:23 Z |
pokmui9909 |
None (KOI16_treeM) |
C++17 |
|
135 ms |
21920 KB |
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
ll n, Q;
ll p[200005];
vector<ll> ans;
struct st
{
ll t, x, y;
}qry[400005];
ll uf[200005];
ll Find(ll n)
{
if (uf[n] == -1) return n;
return uf[n] = Find(uf[n]);
}
void Union(ll x, ll y)
{
x = Find(x), y = Find(y);
uf[y] = x;
}
int main()
{
cin.tie(0); cout.tie(0);
ios_base::sync_with_stdio(false);
cin >> n >> Q;
fill(uf, uf + 200005, -1);
for (ll i = 2; i <= n; i++) cin >> p[i];
for (ll i = 1; i < n + Q; i++)
{
ll op; cin >> op;
if (op == 0)
{
ll x; cin >> x;
qry[i] = { 0, x, 0 };
}
else
{
ll x, y; cin >> x >> y;
qry[i] = { 1, x, y };
}
}
for (ll i = n + Q - 1; i >= 1; i--)
{
if (qry[i].t == 0) Union(qry[i].x, p[qry[i].x]);
else ans.push_back(Find(qry[i].x) == Find(qry[i].y));
}
reverse(ans.begin(), ans.end());
for (auto i : ans) cout << (i ? "YES\n" : "NO\n");
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
2004 KB |
Output is correct |
3 |
Correct |
2 ms |
2004 KB |
Output is correct |
4 |
Correct |
2 ms |
1940 KB |
Output is correct |
5 |
Correct |
2 ms |
2004 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1944 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
2004 KB |
Output is correct |
10 |
Correct |
1 ms |
1880 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
1888 KB |
Output is correct |
21 |
Correct |
2 ms |
1876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
2004 KB |
Output is correct |
3 |
Correct |
2 ms |
2004 KB |
Output is correct |
4 |
Correct |
2 ms |
1940 KB |
Output is correct |
5 |
Correct |
2 ms |
2004 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1944 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
2004 KB |
Output is correct |
10 |
Correct |
1 ms |
1880 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
1888 KB |
Output is correct |
21 |
Correct |
2 ms |
1876 KB |
Output is correct |
22 |
Correct |
48 ms |
11240 KB |
Output is correct |
23 |
Correct |
45 ms |
11204 KB |
Output is correct |
24 |
Correct |
51 ms |
11132 KB |
Output is correct |
25 |
Correct |
47 ms |
11200 KB |
Output is correct |
26 |
Correct |
48 ms |
11204 KB |
Output is correct |
27 |
Correct |
49 ms |
11300 KB |
Output is correct |
28 |
Correct |
54 ms |
11172 KB |
Output is correct |
29 |
Correct |
45 ms |
11248 KB |
Output is correct |
30 |
Correct |
47 ms |
11320 KB |
Output is correct |
31 |
Correct |
46 ms |
11296 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
20664 KB |
Output is correct |
2 |
Correct |
98 ms |
20576 KB |
Output is correct |
3 |
Correct |
107 ms |
20592 KB |
Output is correct |
4 |
Correct |
107 ms |
20564 KB |
Output is correct |
5 |
Correct |
97 ms |
20560 KB |
Output is correct |
6 |
Correct |
101 ms |
20588 KB |
Output is correct |
7 |
Correct |
108 ms |
20676 KB |
Output is correct |
8 |
Correct |
97 ms |
21004 KB |
Output is correct |
9 |
Correct |
94 ms |
20620 KB |
Output is correct |
10 |
Correct |
99 ms |
21844 KB |
Output is correct |
11 |
Correct |
96 ms |
20652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
1876 KB |
Output is correct |
2 |
Correct |
2 ms |
2004 KB |
Output is correct |
3 |
Correct |
2 ms |
2004 KB |
Output is correct |
4 |
Correct |
2 ms |
1940 KB |
Output is correct |
5 |
Correct |
2 ms |
2004 KB |
Output is correct |
6 |
Correct |
2 ms |
1876 KB |
Output is correct |
7 |
Correct |
2 ms |
1944 KB |
Output is correct |
8 |
Correct |
1 ms |
1876 KB |
Output is correct |
9 |
Correct |
2 ms |
2004 KB |
Output is correct |
10 |
Correct |
1 ms |
1880 KB |
Output is correct |
11 |
Correct |
2 ms |
1876 KB |
Output is correct |
12 |
Correct |
2 ms |
1876 KB |
Output is correct |
13 |
Correct |
2 ms |
1876 KB |
Output is correct |
14 |
Correct |
2 ms |
1876 KB |
Output is correct |
15 |
Correct |
1 ms |
1880 KB |
Output is correct |
16 |
Correct |
1 ms |
1876 KB |
Output is correct |
17 |
Correct |
2 ms |
1884 KB |
Output is correct |
18 |
Correct |
2 ms |
1876 KB |
Output is correct |
19 |
Correct |
2 ms |
2004 KB |
Output is correct |
20 |
Correct |
2 ms |
1888 KB |
Output is correct |
21 |
Correct |
2 ms |
1876 KB |
Output is correct |
22 |
Correct |
48 ms |
11240 KB |
Output is correct |
23 |
Correct |
45 ms |
11204 KB |
Output is correct |
24 |
Correct |
51 ms |
11132 KB |
Output is correct |
25 |
Correct |
47 ms |
11200 KB |
Output is correct |
26 |
Correct |
48 ms |
11204 KB |
Output is correct |
27 |
Correct |
49 ms |
11300 KB |
Output is correct |
28 |
Correct |
54 ms |
11172 KB |
Output is correct |
29 |
Correct |
45 ms |
11248 KB |
Output is correct |
30 |
Correct |
47 ms |
11320 KB |
Output is correct |
31 |
Correct |
46 ms |
11296 KB |
Output is correct |
32 |
Correct |
101 ms |
20664 KB |
Output is correct |
33 |
Correct |
98 ms |
20576 KB |
Output is correct |
34 |
Correct |
107 ms |
20592 KB |
Output is correct |
35 |
Correct |
107 ms |
20564 KB |
Output is correct |
36 |
Correct |
97 ms |
20560 KB |
Output is correct |
37 |
Correct |
101 ms |
20588 KB |
Output is correct |
38 |
Correct |
108 ms |
20676 KB |
Output is correct |
39 |
Correct |
97 ms |
21004 KB |
Output is correct |
40 |
Correct |
94 ms |
20620 KB |
Output is correct |
41 |
Correct |
99 ms |
21844 KB |
Output is correct |
42 |
Correct |
96 ms |
20652 KB |
Output is correct |
43 |
Correct |
122 ms |
21204 KB |
Output is correct |
44 |
Correct |
135 ms |
21204 KB |
Output is correct |
45 |
Correct |
113 ms |
21220 KB |
Output is correct |
46 |
Correct |
105 ms |
21196 KB |
Output is correct |
47 |
Correct |
128 ms |
21272 KB |
Output is correct |
48 |
Correct |
101 ms |
21068 KB |
Output is correct |
49 |
Correct |
97 ms |
21228 KB |
Output is correct |
50 |
Correct |
103 ms |
21240 KB |
Output is correct |
51 |
Correct |
107 ms |
21920 KB |
Output is correct |