# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
140675 |
2019-08-04T12:03:17 Z |
khrbuddy03 |
None (KOI16_treeM) |
C++14 |
|
185 ms |
25816 KB |
#include <bits/stdc++.h>
using namespace std;
const int inf = 2e5 + 9;
int par[inf];
struct query {
int a, b, c;
query(int _a, int _b, int _c) : a(_a), b(_b), c(_c) {}
};
struct ds {
int par[inf];
int find(int u) {
if (u == par[u]) return u;
return par[u] = find(par[u]);
}
void merge(int u, int v) {
u = find(u); v = find(v);
if (u == v) return;
par[u] = v;
}
} tree;
int main() {
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n, m; cin >> n >> m;
for (int i = 1; i <= n; i++) tree.par[i] = i;
for (int i = 2; i <= n; i++) cin >> par[i];
vector<query> queries;
for (int i = 0; i < n - 1 + m; i++) {
int x; cin >> x;
if (x == 0) {
int a; cin >> a;
queries.emplace_back(0, a, 0);
} else {
int a, b; cin >> a >> b;
queries.emplace_back(1, a, b);
}
}
reverse(queries.begin(), queries.end());
vector<string> ans;
for (auto q : queries) {
if (q.a == 0) tree.merge(q.b, par[q.b]);
else {
int u = tree.find(q.b), v = tree.find(q.c);
if (u == v) ans.push_back("YES");
else ans.push_back("NO");
}
}
reverse(ans.begin(), ans.end());
for (auto aa : ans) {
cout << aa << '\n';
}
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
404 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
508 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
404 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
508 KB |
Output is correct |
22 |
Correct |
90 ms |
15324 KB |
Output is correct |
23 |
Correct |
92 ms |
15324 KB |
Output is correct |
24 |
Correct |
90 ms |
15220 KB |
Output is correct |
25 |
Correct |
92 ms |
15292 KB |
Output is correct |
26 |
Correct |
90 ms |
15196 KB |
Output is correct |
27 |
Correct |
94 ms |
15188 KB |
Output is correct |
28 |
Correct |
90 ms |
15228 KB |
Output is correct |
29 |
Correct |
90 ms |
15188 KB |
Output is correct |
30 |
Correct |
94 ms |
15316 KB |
Output is correct |
31 |
Correct |
91 ms |
15320 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
173 ms |
24448 KB |
Output is correct |
2 |
Correct |
170 ms |
24420 KB |
Output is correct |
3 |
Correct |
168 ms |
24508 KB |
Output is correct |
4 |
Correct |
171 ms |
24580 KB |
Output is correct |
5 |
Correct |
173 ms |
24532 KB |
Output is correct |
6 |
Correct |
168 ms |
24452 KB |
Output is correct |
7 |
Correct |
168 ms |
24480 KB |
Output is correct |
8 |
Correct |
170 ms |
24876 KB |
Output is correct |
9 |
Correct |
171 ms |
25816 KB |
Output is correct |
10 |
Correct |
168 ms |
24408 KB |
Output is correct |
11 |
Correct |
166 ms |
24372 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
508 KB |
Output is correct |
2 |
Correct |
3 ms |
504 KB |
Output is correct |
3 |
Correct |
3 ms |
504 KB |
Output is correct |
4 |
Correct |
3 ms |
504 KB |
Output is correct |
5 |
Correct |
3 ms |
504 KB |
Output is correct |
6 |
Correct |
3 ms |
504 KB |
Output is correct |
7 |
Correct |
3 ms |
508 KB |
Output is correct |
8 |
Correct |
3 ms |
504 KB |
Output is correct |
9 |
Correct |
3 ms |
504 KB |
Output is correct |
10 |
Correct |
3 ms |
504 KB |
Output is correct |
11 |
Correct |
3 ms |
504 KB |
Output is correct |
12 |
Correct |
3 ms |
504 KB |
Output is correct |
13 |
Correct |
3 ms |
504 KB |
Output is correct |
14 |
Correct |
3 ms |
504 KB |
Output is correct |
15 |
Correct |
3 ms |
504 KB |
Output is correct |
16 |
Correct |
3 ms |
504 KB |
Output is correct |
17 |
Correct |
3 ms |
504 KB |
Output is correct |
18 |
Correct |
3 ms |
504 KB |
Output is correct |
19 |
Correct |
3 ms |
404 KB |
Output is correct |
20 |
Correct |
3 ms |
504 KB |
Output is correct |
21 |
Correct |
3 ms |
508 KB |
Output is correct |
22 |
Correct |
90 ms |
15324 KB |
Output is correct |
23 |
Correct |
92 ms |
15324 KB |
Output is correct |
24 |
Correct |
90 ms |
15220 KB |
Output is correct |
25 |
Correct |
92 ms |
15292 KB |
Output is correct |
26 |
Correct |
90 ms |
15196 KB |
Output is correct |
27 |
Correct |
94 ms |
15188 KB |
Output is correct |
28 |
Correct |
90 ms |
15228 KB |
Output is correct |
29 |
Correct |
90 ms |
15188 KB |
Output is correct |
30 |
Correct |
94 ms |
15316 KB |
Output is correct |
31 |
Correct |
91 ms |
15320 KB |
Output is correct |
32 |
Correct |
173 ms |
24448 KB |
Output is correct |
33 |
Correct |
170 ms |
24420 KB |
Output is correct |
34 |
Correct |
168 ms |
24508 KB |
Output is correct |
35 |
Correct |
171 ms |
24580 KB |
Output is correct |
36 |
Correct |
173 ms |
24532 KB |
Output is correct |
37 |
Correct |
168 ms |
24452 KB |
Output is correct |
38 |
Correct |
168 ms |
24480 KB |
Output is correct |
39 |
Correct |
170 ms |
24876 KB |
Output is correct |
40 |
Correct |
171 ms |
25816 KB |
Output is correct |
41 |
Correct |
168 ms |
24408 KB |
Output is correct |
42 |
Correct |
166 ms |
24372 KB |
Output is correct |
43 |
Correct |
182 ms |
25012 KB |
Output is correct |
44 |
Correct |
185 ms |
25160 KB |
Output is correct |
45 |
Correct |
181 ms |
25028 KB |
Output is correct |
46 |
Correct |
170 ms |
25112 KB |
Output is correct |
47 |
Correct |
165 ms |
25048 KB |
Output is correct |
48 |
Correct |
159 ms |
24924 KB |
Output is correct |
49 |
Correct |
173 ms |
25060 KB |
Output is correct |
50 |
Correct |
163 ms |
25016 KB |
Output is correct |
51 |
Correct |
163 ms |
25152 KB |
Output is correct |