# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
159745 | 2019-10-24T12:17:45 Z | geon040702 | None (KOI16_treeM) | C++14 | 181 ms | 14968 KB |
#include <bits/stdc++.h> using namespace std; int Find_Root(int Node); int Tree[200010]; int Parent[200010]; int Input[400010][3]; int answer[400010]; int main(void) { int Node, Ques, ans_cnt, i; scanf("%d %d", &Node, &Ques); ans_cnt = Ques; Tree[1] = Parent[1] = 1; for(i=2;i<=Node;i++) { Tree[i] = i; scanf("%d", &Parent[i]); } for(i=1;i<=Node+Ques-1;i++) { scanf("%d %d", &Input[i][0], &Input[i][1]); if(Input[i][0] == 1) { scanf("%d", &Input[i][2]); } } for(i=Node+Ques-1;i>=1;i--) { if(ans_cnt == 0) { break; } if(Input[i][0] == 0) { Tree[Input[i][1]] = Parent[Input[i][1]]; } else { if(Find_Root(Input[i][1]) == Find_Root(Input[i][2])) { answer[ans_cnt] = 1; } ans_cnt--; } } for(i=1;i<=Ques;i++) { printf("%s\n", answer[i] ? "YES" : "NO"); } return 0; } int Find_Root(int Node) { if(Tree[Node] != Node) { Tree[Node] = Find_Root(Tree[Node]); } return Tree[Node]; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 248 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 380 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 380 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 380 KB | Output is correct |
16 | Correct | 3 ms | 376 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 376 KB | Output is correct |
19 | Correct | 3 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 380 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 248 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 380 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 380 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 380 KB | Output is correct |
16 | Correct | 3 ms | 376 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 376 KB | Output is correct |
19 | Correct | 3 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 380 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 91 ms | 6120 KB | Output is correct |
23 | Correct | 92 ms | 6144 KB | Output is correct |
24 | Correct | 99 ms | 6380 KB | Output is correct |
25 | Correct | 92 ms | 6136 KB | Output is correct |
26 | Correct | 91 ms | 6136 KB | Output is correct |
27 | Correct | 91 ms | 6236 KB | Output is correct |
28 | Correct | 94 ms | 6260 KB | Output is correct |
29 | Correct | 94 ms | 6412 KB | Output is correct |
30 | Correct | 93 ms | 6620 KB | Output is correct |
31 | Correct | 92 ms | 6480 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 175 ms | 12668 KB | Output is correct |
2 | Correct | 174 ms | 12664 KB | Output is correct |
3 | Correct | 175 ms | 12664 KB | Output is correct |
4 | Correct | 175 ms | 12748 KB | Output is correct |
5 | Correct | 174 ms | 12668 KB | Output is correct |
6 | Correct | 174 ms | 14004 KB | Output is correct |
7 | Correct | 174 ms | 14968 KB | Output is correct |
8 | Correct | 177 ms | 14700 KB | Output is correct |
9 | Correct | 177 ms | 14712 KB | Output is correct |
10 | Correct | 177 ms | 14584 KB | Output is correct |
11 | Correct | 173 ms | 13816 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 376 KB | Output is correct |
2 | Correct | 3 ms | 248 KB | Output is correct |
3 | Correct | 3 ms | 376 KB | Output is correct |
4 | Correct | 3 ms | 376 KB | Output is correct |
5 | Correct | 3 ms | 376 KB | Output is correct |
6 | Correct | 3 ms | 376 KB | Output is correct |
7 | Correct | 3 ms | 380 KB | Output is correct |
8 | Correct | 3 ms | 376 KB | Output is correct |
9 | Correct | 3 ms | 376 KB | Output is correct |
10 | Correct | 3 ms | 376 KB | Output is correct |
11 | Correct | 3 ms | 376 KB | Output is correct |
12 | Correct | 3 ms | 380 KB | Output is correct |
13 | Correct | 3 ms | 376 KB | Output is correct |
14 | Correct | 3 ms | 376 KB | Output is correct |
15 | Correct | 3 ms | 380 KB | Output is correct |
16 | Correct | 3 ms | 376 KB | Output is correct |
17 | Correct | 3 ms | 376 KB | Output is correct |
18 | Correct | 3 ms | 376 KB | Output is correct |
19 | Correct | 3 ms | 376 KB | Output is correct |
20 | Correct | 2 ms | 380 KB | Output is correct |
21 | Correct | 2 ms | 376 KB | Output is correct |
22 | Correct | 91 ms | 6120 KB | Output is correct |
23 | Correct | 92 ms | 6144 KB | Output is correct |
24 | Correct | 99 ms | 6380 KB | Output is correct |
25 | Correct | 92 ms | 6136 KB | Output is correct |
26 | Correct | 91 ms | 6136 KB | Output is correct |
27 | Correct | 91 ms | 6236 KB | Output is correct |
28 | Correct | 94 ms | 6260 KB | Output is correct |
29 | Correct | 94 ms | 6412 KB | Output is correct |
30 | Correct | 93 ms | 6620 KB | Output is correct |
31 | Correct | 92 ms | 6480 KB | Output is correct |
32 | Correct | 175 ms | 12668 KB | Output is correct |
33 | Correct | 174 ms | 12664 KB | Output is correct |
34 | Correct | 175 ms | 12664 KB | Output is correct |
35 | Correct | 175 ms | 12748 KB | Output is correct |
36 | Correct | 174 ms | 12668 KB | Output is correct |
37 | Correct | 174 ms | 14004 KB | Output is correct |
38 | Correct | 174 ms | 14968 KB | Output is correct |
39 | Correct | 177 ms | 14700 KB | Output is correct |
40 | Correct | 177 ms | 14712 KB | Output is correct |
41 | Correct | 177 ms | 14584 KB | Output is correct |
42 | Correct | 173 ms | 13816 KB | Output is correct |
43 | Correct | 181 ms | 13532 KB | Output is correct |
44 | Correct | 181 ms | 13536 KB | Output is correct |
45 | Correct | 181 ms | 13560 KB | Output is correct |
46 | Correct | 170 ms | 13688 KB | Output is correct |
47 | Correct | 171 ms | 13688 KB | Output is correct |
48 | Correct | 163 ms | 13392 KB | Output is correct |
49 | Correct | 172 ms | 13404 KB | Output is correct |
50 | Correct | 169 ms | 13404 KB | Output is correct |
51 | Correct | 164 ms | 14304 KB | Output is correct |