# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
56864 | 2018-07-13T00:11:01 Z | red1108 | None (KOI16_treeM) | C++17 | 237 ms | 65420 KB |
#include <stdio.h> #include <stack> using namespace std; stack<bool> ans; int bumo[200010], input[500010][3], par[200010]; int n, q; int pfind(int x) { if(par[x]==x) return x; return par[x]=pfind(par[x]); } void uni(int a, int b) { par[pfind(a)]=pfind(b); } int main() { int i, a, b; scanf("%d %d", &n, &q); par[1]=1; for(i=2;i<=n;i++) { par[i]=i; scanf("%d", &bumo[i]); } for(i=1;i<=q+n-1;i++) { scanf("%d %d", &input[i][0], &input[i][1]); if(input[i][0]==1) { scanf("%d", &input[i][2]); } } for(i=q+n-1;i>=1;i--) { if(input[i][0]==1) { if(pfind(input[i][1])==pfind(input[i][2])) { ans.push(1); } else ans.push(0); } else { uni(input[i][1],bumo[input[i][1]]); } } while(!ans.empty()) { printf("%s\n",ans.top()==1?"YES":"NO"); ans.pop(); } }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 292 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 4 ms | 504 KB | Output is correct |
4 | Correct | 4 ms | 504 KB | Output is correct |
5 | Correct | 4 ms | 508 KB | Output is correct |
6 | Correct | 4 ms | 616 KB | Output is correct |
7 | Correct | 3 ms | 616 KB | Output is correct |
8 | Correct | 4 ms | 668 KB | Output is correct |
9 | Correct | 5 ms | 676 KB | Output is correct |
10 | Correct | 4 ms | 684 KB | Output is correct |
11 | Correct | 3 ms | 692 KB | Output is correct |
12 | Correct | 3 ms | 700 KB | Output is correct |
13 | Correct | 4 ms | 836 KB | Output is correct |
14 | Correct | 4 ms | 836 KB | Output is correct |
15 | Correct | 4 ms | 836 KB | Output is correct |
16 | Correct | 3 ms | 836 KB | Output is correct |
17 | Correct | 4 ms | 836 KB | Output is correct |
18 | Correct | 3 ms | 836 KB | Output is correct |
19 | Correct | 3 ms | 836 KB | Output is correct |
20 | Correct | 3 ms | 836 KB | Output is correct |
21 | Correct | 4 ms | 836 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 292 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 4 ms | 504 KB | Output is correct |
4 | Correct | 4 ms | 504 KB | Output is correct |
5 | Correct | 4 ms | 508 KB | Output is correct |
6 | Correct | 4 ms | 616 KB | Output is correct |
7 | Correct | 3 ms | 616 KB | Output is correct |
8 | Correct | 4 ms | 668 KB | Output is correct |
9 | Correct | 5 ms | 676 KB | Output is correct |
10 | Correct | 4 ms | 684 KB | Output is correct |
11 | Correct | 3 ms | 692 KB | Output is correct |
12 | Correct | 3 ms | 700 KB | Output is correct |
13 | Correct | 4 ms | 836 KB | Output is correct |
14 | Correct | 4 ms | 836 KB | Output is correct |
15 | Correct | 4 ms | 836 KB | Output is correct |
16 | Correct | 3 ms | 836 KB | Output is correct |
17 | Correct | 4 ms | 836 KB | Output is correct |
18 | Correct | 3 ms | 836 KB | Output is correct |
19 | Correct | 3 ms | 836 KB | Output is correct |
20 | Correct | 3 ms | 836 KB | Output is correct |
21 | Correct | 4 ms | 836 KB | Output is correct |
22 | Correct | 98 ms | 3996 KB | Output is correct |
23 | Correct | 95 ms | 4012 KB | Output is correct |
24 | Correct | 95 ms | 4012 KB | Output is correct |
25 | Correct | 94 ms | 4012 KB | Output is correct |
26 | Correct | 94 ms | 4124 KB | Output is correct |
27 | Correct | 141 ms | 4124 KB | Output is correct |
28 | Correct | 115 ms | 4176 KB | Output is correct |
29 | Correct | 91 ms | 4188 KB | Output is correct |
30 | Correct | 88 ms | 4188 KB | Output is correct |
31 | Correct | 106 ms | 4188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 189 ms | 10556 KB | Output is correct |
2 | Correct | 185 ms | 10556 KB | Output is correct |
3 | Correct | 185 ms | 10556 KB | Output is correct |
4 | Correct | 199 ms | 10556 KB | Output is correct |
5 | Correct | 203 ms | 10556 KB | Output is correct |
6 | Correct | 230 ms | 10556 KB | Output is correct |
7 | Correct | 184 ms | 10556 KB | Output is correct |
8 | Correct | 219 ms | 10832 KB | Output is correct |
9 | Correct | 198 ms | 11660 KB | Output is correct |
10 | Correct | 206 ms | 11660 KB | Output is correct |
11 | Correct | 198 ms | 11660 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 4 ms | 292 KB | Output is correct |
2 | Correct | 3 ms | 504 KB | Output is correct |
3 | Correct | 4 ms | 504 KB | Output is correct |
4 | Correct | 4 ms | 504 KB | Output is correct |
5 | Correct | 4 ms | 508 KB | Output is correct |
6 | Correct | 4 ms | 616 KB | Output is correct |
7 | Correct | 3 ms | 616 KB | Output is correct |
8 | Correct | 4 ms | 668 KB | Output is correct |
9 | Correct | 5 ms | 676 KB | Output is correct |
10 | Correct | 4 ms | 684 KB | Output is correct |
11 | Correct | 3 ms | 692 KB | Output is correct |
12 | Correct | 3 ms | 700 KB | Output is correct |
13 | Correct | 4 ms | 836 KB | Output is correct |
14 | Correct | 4 ms | 836 KB | Output is correct |
15 | Correct | 4 ms | 836 KB | Output is correct |
16 | Correct | 3 ms | 836 KB | Output is correct |
17 | Correct | 4 ms | 836 KB | Output is correct |
18 | Correct | 3 ms | 836 KB | Output is correct |
19 | Correct | 3 ms | 836 KB | Output is correct |
20 | Correct | 3 ms | 836 KB | Output is correct |
21 | Correct | 4 ms | 836 KB | Output is correct |
22 | Correct | 98 ms | 3996 KB | Output is correct |
23 | Correct | 95 ms | 4012 KB | Output is correct |
24 | Correct | 95 ms | 4012 KB | Output is correct |
25 | Correct | 94 ms | 4012 KB | Output is correct |
26 | Correct | 94 ms | 4124 KB | Output is correct |
27 | Correct | 141 ms | 4124 KB | Output is correct |
28 | Correct | 115 ms | 4176 KB | Output is correct |
29 | Correct | 91 ms | 4188 KB | Output is correct |
30 | Correct | 88 ms | 4188 KB | Output is correct |
31 | Correct | 106 ms | 4188 KB | Output is correct |
32 | Correct | 189 ms | 10556 KB | Output is correct |
33 | Correct | 185 ms | 10556 KB | Output is correct |
34 | Correct | 185 ms | 10556 KB | Output is correct |
35 | Correct | 199 ms | 10556 KB | Output is correct |
36 | Correct | 203 ms | 10556 KB | Output is correct |
37 | Correct | 230 ms | 10556 KB | Output is correct |
38 | Correct | 184 ms | 10556 KB | Output is correct |
39 | Correct | 219 ms | 10832 KB | Output is correct |
40 | Correct | 198 ms | 11660 KB | Output is correct |
41 | Correct | 206 ms | 11660 KB | Output is correct |
42 | Correct | 198 ms | 11660 KB | Output is correct |
43 | Correct | 227 ms | 16664 KB | Output is correct |
44 | Correct | 208 ms | 22744 KB | Output is correct |
45 | Correct | 237 ms | 28764 KB | Output is correct |
46 | Correct | 225 ms | 34964 KB | Output is correct |
47 | Correct | 174 ms | 41028 KB | Output is correct |
48 | Correct | 174 ms | 47096 KB | Output is correct |
49 | Correct | 200 ms | 53256 KB | Output is correct |
50 | Correct | 184 ms | 59228 KB | Output is correct |
51 | Correct | 201 ms | 65420 KB | Output is correct |