# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
544668 |
2022-04-02T14:18:59 Z |
pokmui9909 |
None (KOI16_treeM) |
C++17 |
|
124 ms |
65536 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 + 1, uf + n + 1, -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 |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
392 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
396 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
392 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
396 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
47 ms |
9676 KB |
Output is correct |
23 |
Correct |
50 ms |
9676 KB |
Output is correct |
24 |
Correct |
51 ms |
9648 KB |
Output is correct |
25 |
Correct |
46 ms |
9676 KB |
Output is correct |
26 |
Correct |
53 ms |
9676 KB |
Output is correct |
27 |
Correct |
49 ms |
9668 KB |
Output is correct |
28 |
Correct |
49 ms |
9764 KB |
Output is correct |
29 |
Correct |
48 ms |
9708 KB |
Output is correct |
30 |
Correct |
46 ms |
9880 KB |
Output is correct |
31 |
Correct |
47 ms |
9720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
101 ms |
20600 KB |
Output is correct |
2 |
Correct |
99 ms |
20576 KB |
Output is correct |
3 |
Correct |
101 ms |
20584 KB |
Output is correct |
4 |
Correct |
105 ms |
20668 KB |
Output is correct |
5 |
Correct |
99 ms |
20676 KB |
Output is correct |
6 |
Correct |
101 ms |
20612 KB |
Output is correct |
7 |
Correct |
100 ms |
20588 KB |
Output is correct |
8 |
Correct |
101 ms |
21000 KB |
Output is correct |
9 |
Runtime error |
124 ms |
65536 KB |
Execution killed with signal 9 |
10 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
392 KB |
Output is correct |
4 |
Correct |
1 ms |
340 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
340 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
1 ms |
340 KB |
Output is correct |
10 |
Correct |
1 ms |
340 KB |
Output is correct |
11 |
Correct |
1 ms |
340 KB |
Output is correct |
12 |
Correct |
1 ms |
352 KB |
Output is correct |
13 |
Correct |
1 ms |
340 KB |
Output is correct |
14 |
Correct |
1 ms |
340 KB |
Output is correct |
15 |
Correct |
1 ms |
340 KB |
Output is correct |
16 |
Correct |
1 ms |
340 KB |
Output is correct |
17 |
Correct |
1 ms |
360 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
396 KB |
Output is correct |
20 |
Correct |
1 ms |
352 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
47 ms |
9676 KB |
Output is correct |
23 |
Correct |
50 ms |
9676 KB |
Output is correct |
24 |
Correct |
51 ms |
9648 KB |
Output is correct |
25 |
Correct |
46 ms |
9676 KB |
Output is correct |
26 |
Correct |
53 ms |
9676 KB |
Output is correct |
27 |
Correct |
49 ms |
9668 KB |
Output is correct |
28 |
Correct |
49 ms |
9764 KB |
Output is correct |
29 |
Correct |
48 ms |
9708 KB |
Output is correct |
30 |
Correct |
46 ms |
9880 KB |
Output is correct |
31 |
Correct |
47 ms |
9720 KB |
Output is correct |
32 |
Correct |
101 ms |
20600 KB |
Output is correct |
33 |
Correct |
99 ms |
20576 KB |
Output is correct |
34 |
Correct |
101 ms |
20584 KB |
Output is correct |
35 |
Correct |
105 ms |
20668 KB |
Output is correct |
36 |
Correct |
99 ms |
20676 KB |
Output is correct |
37 |
Correct |
101 ms |
20612 KB |
Output is correct |
38 |
Correct |
100 ms |
20588 KB |
Output is correct |
39 |
Correct |
101 ms |
21000 KB |
Output is correct |
40 |
Runtime error |
124 ms |
65536 KB |
Execution killed with signal 9 |
41 |
Halted |
0 ms |
0 KB |
- |