# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
99544 |
2019-03-05T00:51:53 Z |
jhnah917 |
None (KOI16_treeM) |
C++14 |
|
187 ms |
14456 KB |
#include <bits/stdc++.h>
using namespace std;
int parent[200020];
int level[200020];
int g[200020];
int n;
int query[400010][3];
void init(){
for(int i=0; i<=200000; i++){
parent[i] = i;
level[i] = 1;
}
}
int find(int u){
if(u == parent[u]) return u;
return parent[u] = find(parent[u]);
}
void merge(int u, int v){
u = find(u);
v = find(v);
if(u == v) return;
if(level[u] > level[v]) swap(u, v);
parent[u] = v;
if(level[u] == level[v]) level[v]++;
}
int main(){
ios_base::sync_with_stdio(0); //cin.tie(0);
int n, q; cin >> n >> q;
g[1] = 1;
for(int i=2; i<=n; i++){
int t; cin >> t;
g[i] = t;
}
init();
q += (n-1);
for(int i=0; i<q; i++){
int op; cin >> op;
if(op) cin >> query[i][1] >> query[i][2];
else{
cin >> query[i][1]; query[i][2] = 0;
}
}
stack<bool> s;
for(int i=q-1; i>=0; i--){
if(query[i][2]){
if(find(query[i][1]) == find(query[i][2])) s.push(true);
else s.push(false);
}else{
merge(query[i][1], g[query[i][1]]);
}
}
while(!s.empty()){
cout << (s.top()?"YES":"NO") << "\n"; s.pop();
}
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
2048 KB |
Output is correct |
3 |
Correct |
4 ms |
2048 KB |
Output is correct |
4 |
Correct |
4 ms |
2020 KB |
Output is correct |
5 |
Correct |
4 ms |
1920 KB |
Output is correct |
6 |
Correct |
5 ms |
1920 KB |
Output is correct |
7 |
Correct |
4 ms |
1920 KB |
Output is correct |
8 |
Correct |
4 ms |
2048 KB |
Output is correct |
9 |
Correct |
3 ms |
1920 KB |
Output is correct |
10 |
Correct |
5 ms |
2048 KB |
Output is correct |
11 |
Correct |
6 ms |
1920 KB |
Output is correct |
12 |
Correct |
5 ms |
2048 KB |
Output is correct |
13 |
Correct |
5 ms |
2048 KB |
Output is correct |
14 |
Correct |
4 ms |
1920 KB |
Output is correct |
15 |
Correct |
4 ms |
2048 KB |
Output is correct |
16 |
Correct |
5 ms |
2048 KB |
Output is correct |
17 |
Correct |
5 ms |
2048 KB |
Output is correct |
18 |
Correct |
4 ms |
1980 KB |
Output is correct |
19 |
Correct |
4 ms |
2048 KB |
Output is correct |
20 |
Correct |
4 ms |
2048 KB |
Output is correct |
21 |
Correct |
5 ms |
2048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
2048 KB |
Output is correct |
3 |
Correct |
4 ms |
2048 KB |
Output is correct |
4 |
Correct |
4 ms |
2020 KB |
Output is correct |
5 |
Correct |
4 ms |
1920 KB |
Output is correct |
6 |
Correct |
5 ms |
1920 KB |
Output is correct |
7 |
Correct |
4 ms |
1920 KB |
Output is correct |
8 |
Correct |
4 ms |
2048 KB |
Output is correct |
9 |
Correct |
3 ms |
1920 KB |
Output is correct |
10 |
Correct |
5 ms |
2048 KB |
Output is correct |
11 |
Correct |
6 ms |
1920 KB |
Output is correct |
12 |
Correct |
5 ms |
2048 KB |
Output is correct |
13 |
Correct |
5 ms |
2048 KB |
Output is correct |
14 |
Correct |
4 ms |
1920 KB |
Output is correct |
15 |
Correct |
4 ms |
2048 KB |
Output is correct |
16 |
Correct |
5 ms |
2048 KB |
Output is correct |
17 |
Correct |
5 ms |
2048 KB |
Output is correct |
18 |
Correct |
4 ms |
1980 KB |
Output is correct |
19 |
Correct |
4 ms |
2048 KB |
Output is correct |
20 |
Correct |
4 ms |
2048 KB |
Output is correct |
21 |
Correct |
5 ms |
2048 KB |
Output is correct |
22 |
Correct |
65 ms |
7460 KB |
Output is correct |
23 |
Correct |
65 ms |
7352 KB |
Output is correct |
24 |
Correct |
72 ms |
7484 KB |
Output is correct |
25 |
Correct |
63 ms |
7288 KB |
Output is correct |
26 |
Correct |
65 ms |
7340 KB |
Output is correct |
27 |
Correct |
65 ms |
7452 KB |
Output is correct |
28 |
Correct |
72 ms |
7416 KB |
Output is correct |
29 |
Correct |
65 ms |
7400 KB |
Output is correct |
30 |
Correct |
103 ms |
7544 KB |
Output is correct |
31 |
Correct |
74 ms |
7608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
136 ms |
13688 KB |
Output is correct |
2 |
Correct |
127 ms |
13688 KB |
Output is correct |
3 |
Correct |
178 ms |
13688 KB |
Output is correct |
4 |
Correct |
136 ms |
13676 KB |
Output is correct |
5 |
Correct |
147 ms |
13688 KB |
Output is correct |
6 |
Correct |
130 ms |
13824 KB |
Output is correct |
7 |
Correct |
152 ms |
13764 KB |
Output is correct |
8 |
Correct |
135 ms |
13784 KB |
Output is correct |
9 |
Correct |
175 ms |
13816 KB |
Output is correct |
10 |
Correct |
167 ms |
13820 KB |
Output is correct |
11 |
Correct |
187 ms |
13716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Correct |
4 ms |
2048 KB |
Output is correct |
3 |
Correct |
4 ms |
2048 KB |
Output is correct |
4 |
Correct |
4 ms |
2020 KB |
Output is correct |
5 |
Correct |
4 ms |
1920 KB |
Output is correct |
6 |
Correct |
5 ms |
1920 KB |
Output is correct |
7 |
Correct |
4 ms |
1920 KB |
Output is correct |
8 |
Correct |
4 ms |
2048 KB |
Output is correct |
9 |
Correct |
3 ms |
1920 KB |
Output is correct |
10 |
Correct |
5 ms |
2048 KB |
Output is correct |
11 |
Correct |
6 ms |
1920 KB |
Output is correct |
12 |
Correct |
5 ms |
2048 KB |
Output is correct |
13 |
Correct |
5 ms |
2048 KB |
Output is correct |
14 |
Correct |
4 ms |
1920 KB |
Output is correct |
15 |
Correct |
4 ms |
2048 KB |
Output is correct |
16 |
Correct |
5 ms |
2048 KB |
Output is correct |
17 |
Correct |
5 ms |
2048 KB |
Output is correct |
18 |
Correct |
4 ms |
1980 KB |
Output is correct |
19 |
Correct |
4 ms |
2048 KB |
Output is correct |
20 |
Correct |
4 ms |
2048 KB |
Output is correct |
21 |
Correct |
5 ms |
2048 KB |
Output is correct |
22 |
Correct |
65 ms |
7460 KB |
Output is correct |
23 |
Correct |
65 ms |
7352 KB |
Output is correct |
24 |
Correct |
72 ms |
7484 KB |
Output is correct |
25 |
Correct |
63 ms |
7288 KB |
Output is correct |
26 |
Correct |
65 ms |
7340 KB |
Output is correct |
27 |
Correct |
65 ms |
7452 KB |
Output is correct |
28 |
Correct |
72 ms |
7416 KB |
Output is correct |
29 |
Correct |
65 ms |
7400 KB |
Output is correct |
30 |
Correct |
103 ms |
7544 KB |
Output is correct |
31 |
Correct |
74 ms |
7608 KB |
Output is correct |
32 |
Correct |
136 ms |
13688 KB |
Output is correct |
33 |
Correct |
127 ms |
13688 KB |
Output is correct |
34 |
Correct |
178 ms |
13688 KB |
Output is correct |
35 |
Correct |
136 ms |
13676 KB |
Output is correct |
36 |
Correct |
147 ms |
13688 KB |
Output is correct |
37 |
Correct |
130 ms |
13824 KB |
Output is correct |
38 |
Correct |
152 ms |
13764 KB |
Output is correct |
39 |
Correct |
135 ms |
13784 KB |
Output is correct |
40 |
Correct |
175 ms |
13816 KB |
Output is correct |
41 |
Correct |
167 ms |
13820 KB |
Output is correct |
42 |
Correct |
187 ms |
13716 KB |
Output is correct |
43 |
Correct |
170 ms |
14304 KB |
Output is correct |
44 |
Correct |
154 ms |
14328 KB |
Output is correct |
45 |
Correct |
149 ms |
14328 KB |
Output is correct |
46 |
Correct |
148 ms |
14456 KB |
Output is correct |
47 |
Correct |
133 ms |
14328 KB |
Output is correct |
48 |
Correct |
122 ms |
14200 KB |
Output is correct |
49 |
Correct |
147 ms |
14436 KB |
Output is correct |
50 |
Correct |
143 ms |
14436 KB |
Output is correct |
51 |
Correct |
124 ms |
14328 KB |
Output is correct |