# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
20826 | 2017-02-20T13:56:08 Z | model_code | None (KOI16_treeM) | C++11 | 1169 ms | 20280 KB |
#include<stdio.h> #include<vector> #include<deque> #define MAX 200100 using namespace std; struct xy { int x, y; }; int labelw; int label[MAX]; vector<xy>edge[MAX]; deque<int>st1; bool is_gone[MAX]; int cut1, cut2; int parent[MAX]; int ep1[MAX]; int ep2[MAX]; void un_check(int w) { int i; is_gone[w] = 0; for (i = 0; i < edge[w].size(); i++) { if (is_gone[edge[w][i].x] == 0) continue; un_check(edge[w][i].x); } } void labeling(int w) { int i; is_gone[w] = 1; label[w] = labelw; for (i = 0; i < edge[w].size(); i++) { if (edge[w][i].y == 1) continue; if (is_gone[edge[w][i].x]) continue; labeling(edge[w][i].x); } } vector<int>stw[2]; vector<int>sti[2]; int main() { int n, q; int i, j; int a, b; int P; int flag; int noww, nowi; scanf("%d%d", &n, &q); labelw = 1; for (i = 1; i <= n; i++) { label[i] = labelw; } labelw++; parent[1] = -1; for (i = 2; i <= n; i++) { scanf("%d", &parent[i]); ep1[i] = edge[i].size(); ep2[i] = edge[parent[i]].size(); edge[parent[i]].push_back({ i, 0 }); edge[i].push_back({ parent[i], 0 }); } for (i = 0; i < n + q - 1; i++) { scanf("%d", &flag); if (flag == 1) { scanf("%d%d", &a, &b); if (label[a] == label[b]) { printf("YES\n"); } else { printf("NO\n"); } continue; } scanf("%d", &cut1); cut2 = parent[cut1]; if (cut2 == -1) continue; edge[cut1][ep1[cut1]].y = 1; edge[cut2][ep2[cut1]].y = 1; stw[0].push_back(cut1); sti[0].push_back(0); stw[1].push_back(cut2); sti[1].push_back(0); flag = 0; while (1) { if (stw[flag].empty()) break; noww = stw[flag].back(); nowi = sti[flag].back(); stw[flag].pop_back(); sti[flag].pop_back(); is_gone[noww] = 1; while (1) { if (nowi == edge[noww].size()) break; if (edge[noww][nowi].y) { nowi++; continue; } if (is_gone[edge[noww][nowi].x]) { nowi++; continue; } break; } if (nowi == edge[noww].size()) { continue; } stw[flag].push_back(noww); sti[flag].push_back(nowi + 1); stw[flag].push_back(edge[noww][nowi].x); sti[flag].push_back(0); flag = !flag; } stw[0].clear(); sti[0].clear(); stw[1].clear(); sti[1].clear(); un_check(cut1); if (flag == 0) { labeling(cut1); labelw++; un_check(cut1); } else { labeling(cut2); labelw++; un_check(cut2); } } return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 9188 KB | Output is correct |
2 | Correct | 0 ms | 9188 KB | Output is correct |
3 | Correct | 3 ms | 9188 KB | Output is correct |
4 | Correct | 0 ms | 9188 KB | Output is correct |
5 | Correct | 0 ms | 9188 KB | Output is correct |
6 | Correct | 3 ms | 9188 KB | Output is correct |
7 | Correct | 0 ms | 9188 KB | Output is correct |
8 | Correct | 0 ms | 9188 KB | Output is correct |
9 | Correct | 0 ms | 9188 KB | Output is correct |
10 | Correct | 0 ms | 9188 KB | Output is correct |
11 | Correct | 0 ms | 9188 KB | Output is correct |
12 | Correct | 0 ms | 9188 KB | Output is correct |
13 | Correct | 0 ms | 9188 KB | Output is correct |
14 | Correct | 0 ms | 9188 KB | Output is correct |
15 | Correct | 0 ms | 9188 KB | Output is correct |
16 | Correct | 0 ms | 9188 KB | Output is correct |
17 | Correct | 0 ms | 9188 KB | Output is correct |
18 | Correct | 0 ms | 9188 KB | Output is correct |
19 | Correct | 0 ms | 9188 KB | Output is correct |
20 | Correct | 0 ms | 9188 KB | Output is correct |
21 | Correct | 0 ms | 9188 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 9188 KB | Output is correct |
2 | Correct | 0 ms | 9188 KB | Output is correct |
3 | Correct | 3 ms | 9188 KB | Output is correct |
4 | Correct | 0 ms | 9188 KB | Output is correct |
5 | Correct | 0 ms | 9188 KB | Output is correct |
6 | Correct | 3 ms | 9188 KB | Output is correct |
7 | Correct | 0 ms | 9188 KB | Output is correct |
8 | Correct | 0 ms | 9188 KB | Output is correct |
9 | Correct | 0 ms | 9188 KB | Output is correct |
10 | Correct | 0 ms | 9188 KB | Output is correct |
11 | Correct | 0 ms | 9188 KB | Output is correct |
12 | Correct | 0 ms | 9188 KB | Output is correct |
13 | Correct | 0 ms | 9188 KB | Output is correct |
14 | Correct | 0 ms | 9188 KB | Output is correct |
15 | Correct | 0 ms | 9188 KB | Output is correct |
16 | Correct | 0 ms | 9188 KB | Output is correct |
17 | Correct | 0 ms | 9188 KB | Output is correct |
18 | Correct | 0 ms | 9188 KB | Output is correct |
19 | Correct | 0 ms | 9188 KB | Output is correct |
20 | Correct | 0 ms | 9188 KB | Output is correct |
21 | Correct | 0 ms | 9188 KB | Output is correct |
22 | Correct | 83 ms | 9320 KB | Output is correct |
23 | Correct | 76 ms | 9320 KB | Output is correct |
24 | Correct | 96 ms | 9320 KB | Output is correct |
25 | Correct | 73 ms | 9320 KB | Output is correct |
26 | Correct | 83 ms | 9320 KB | Output is correct |
27 | Correct | 76 ms | 9320 KB | Output is correct |
28 | Correct | 83 ms | 9320 KB | Output is correct |
29 | Correct | 76 ms | 9320 KB | Output is correct |
30 | Correct | 83 ms | 9320 KB | Output is correct |
31 | Correct | 99 ms | 9320 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 1169 ms | 20256 KB | Output is correct |
2 | Correct | 949 ms | 19532 KB | Output is correct |
3 | Correct | 1043 ms | 18204 KB | Output is correct |
4 | Correct | 963 ms | 18064 KB | Output is correct |
5 | Correct | 1012 ms | 18028 KB | Output is correct |
6 | Correct | 996 ms | 18156 KB | Output is correct |
7 | Correct | 1113 ms | 20280 KB | Output is correct |
8 | Correct | 333 ms | 15392 KB | Output is correct |
9 | Correct | 326 ms | 15392 KB | Output is correct |
10 | Correct | 356 ms | 15392 KB | Output is correct |
11 | Correct | 1006 ms | 20024 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 3 ms | 9188 KB | Output is correct |
2 | Correct | 0 ms | 9188 KB | Output is correct |
3 | Correct | 3 ms | 9188 KB | Output is correct |
4 | Correct | 0 ms | 9188 KB | Output is correct |
5 | Correct | 0 ms | 9188 KB | Output is correct |
6 | Correct | 3 ms | 9188 KB | Output is correct |
7 | Correct | 0 ms | 9188 KB | Output is correct |
8 | Correct | 0 ms | 9188 KB | Output is correct |
9 | Correct | 0 ms | 9188 KB | Output is correct |
10 | Correct | 0 ms | 9188 KB | Output is correct |
11 | Correct | 0 ms | 9188 KB | Output is correct |
12 | Correct | 0 ms | 9188 KB | Output is correct |
13 | Correct | 0 ms | 9188 KB | Output is correct |
14 | Correct | 0 ms | 9188 KB | Output is correct |
15 | Correct | 0 ms | 9188 KB | Output is correct |
16 | Correct | 0 ms | 9188 KB | Output is correct |
17 | Correct | 0 ms | 9188 KB | Output is correct |
18 | Correct | 0 ms | 9188 KB | Output is correct |
19 | Correct | 0 ms | 9188 KB | Output is correct |
20 | Correct | 0 ms | 9188 KB | Output is correct |
21 | Correct | 0 ms | 9188 KB | Output is correct |
22 | Correct | 83 ms | 9320 KB | Output is correct |
23 | Correct | 76 ms | 9320 KB | Output is correct |
24 | Correct | 96 ms | 9320 KB | Output is correct |
25 | Correct | 73 ms | 9320 KB | Output is correct |
26 | Correct | 83 ms | 9320 KB | Output is correct |
27 | Correct | 76 ms | 9320 KB | Output is correct |
28 | Correct | 83 ms | 9320 KB | Output is correct |
29 | Correct | 76 ms | 9320 KB | Output is correct |
30 | Correct | 83 ms | 9320 KB | Output is correct |
31 | Correct | 99 ms | 9320 KB | Output is correct |
32 | Correct | 1169 ms | 20256 KB | Output is correct |
33 | Correct | 949 ms | 19532 KB | Output is correct |
34 | Correct | 1043 ms | 18204 KB | Output is correct |
35 | Correct | 963 ms | 18064 KB | Output is correct |
36 | Correct | 1012 ms | 18028 KB | Output is correct |
37 | Correct | 996 ms | 18156 KB | Output is correct |
38 | Correct | 1113 ms | 20280 KB | Output is correct |
39 | Correct | 333 ms | 15392 KB | Output is correct |
40 | Correct | 326 ms | 15392 KB | Output is correct |
41 | Correct | 356 ms | 15392 KB | Output is correct |
42 | Correct | 1006 ms | 20024 KB | Output is correct |
43 | Correct | 579 ms | 17504 KB | Output is correct |
44 | Correct | 566 ms | 17504 KB | Output is correct |
45 | Correct | 516 ms | 17504 KB | Output is correct |
46 | Correct | 396 ms | 17504 KB | Output is correct |
47 | Correct | 433 ms | 17504 KB | Output is correct |
48 | Correct | 179 ms | 17480 KB | Output is correct |
49 | Correct | 223 ms | 17996 KB | Output is correct |
50 | Correct | 213 ms | 18096 KB | Output is correct |
51 | Correct | 216 ms | 17992 KB | Output is correct |