# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200063 | 2020-02-05T08:09:48 Z | SamAnd | Tax Evasion (LMIO19_mokesciai) | C++17 | 283 ms | 55020 KB |
#include <bits/stdc++.h> using namespace std; const int N = 200005; int n, m; vector<int> a[N]; bool c[N]; int d[N]; int q[N]; vector<int> v; void dfs(int x) { if (v.empty()) d[x] = 1; else d[x] = d[v.back()] + 1; v.push_back(x); if (c[x]) { int u = (v.size() / 2) - 1; ++q[v[v.size() - u - 1]]; } for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; dfs(h); } v.pop_back(); } struct ban { int x, d; ban(){} ban(int x, int d) { this->x = x; this->d = d; } }; bool operator<(const ban& a, const ban& b) { return a.d < b.d; } priority_queue<ban> u[N]; void dfs1(int x) { u[x].push(ban(x, d[x])); for (int i = 0; i < a[x].size(); ++i) { int h = a[x][i]; dfs1(h); if (u[x].size() < u[h].size()) swap(u[x], u[h]); while (!u[h].empty()) { u[x].push(u[h].top()); u[h].pop(); } } for (int i = 0; i < q[x]; ++i) { c[u[x].top().x] = true; u[x].pop(); } } int main() { scanf("%d%d", &n, &m); for (int i = 2; i <= n; ++i) { int p; scanf("%d", &p); a[p].push_back(i); } for (int i = 0; i < m; ++i) { int x; scanf("%d", &x); c[x] = true; } if (c[1]) { printf("1\n"); return 0; } dfs(1); memset(c, false, sizeof c); dfs1(1); int ans = N; for (int i = 1; i <= n; ++i) { if (c[i]) ans = min(ans, d[i]); } printf("%d\n", ans); return 0; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 11512 KB | Output is correct |
2 | Correct | 11 ms | 11512 KB | Output is correct |
3 | Correct | 14 ms | 12408 KB | Output is correct |
4 | Correct | 14 ms | 12536 KB | Output is correct |
5 | Correct | 14 ms | 12536 KB | Output is correct |
6 | Correct | 94 ms | 54120 KB | Output is correct |
7 | Correct | 94 ms | 54120 KB | Output is correct |
8 | Correct | 13 ms | 12536 KB | Output is correct |
9 | Correct | 136 ms | 54740 KB | Output is correct |
10 | Correct | 151 ms | 55020 KB | Output is correct |
11 | Correct | 121 ms | 54892 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 12 ms | 11512 KB | Output is correct |
2 | Correct | 13 ms | 12152 KB | Output is correct |
3 | Correct | 13 ms | 12152 KB | Output is correct |
4 | Correct | 13 ms | 11768 KB | Output is correct |
5 | Correct | 13 ms | 12024 KB | Output is correct |
6 | Correct | 15 ms | 12024 KB | Output is correct |
7 | Correct | 94 ms | 54120 KB | Output is correct |
8 | Correct | 94 ms | 54120 KB | Output is correct |
9 | Correct | 13 ms | 12536 KB | Output is correct |
10 | Correct | 88 ms | 37352 KB | Output is correct |
11 | Correct | 90 ms | 37356 KB | Output is correct |
12 | Correct | 142 ms | 24800 KB | Output is correct |
13 | Correct | 95 ms | 39280 KB | Output is correct |
14 | Correct | 185 ms | 36928 KB | Output is correct |
15 | Correct | 150 ms | 24964 KB | Output is correct |
16 | Correct | 95 ms | 39148 KB | Output is correct |
17 | Correct | 264 ms | 32208 KB | Output is correct |
18 | Correct | 101 ms | 44392 KB | Output is correct |
19 | Correct | 107 ms | 30952 KB | Output is correct |
20 | Correct | 105 ms | 29668 KB | Output is correct |
21 | Correct | 105 ms | 29412 KB | Output is correct |
22 | Correct | 104 ms | 29668 KB | Output is correct |
23 | Correct | 113 ms | 29924 KB | Output is correct |
24 | Correct | 101 ms | 29540 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 11516 KB | Output is correct |
2 | Correct | 11 ms | 11516 KB | Output is correct |
3 | Correct | 12 ms | 11512 KB | Output is correct |
4 | Correct | 12 ms | 11512 KB | Output is correct |
5 | Correct | 13 ms | 11512 KB | Output is correct |
6 | Correct | 13 ms | 12152 KB | Output is correct |
7 | Correct | 14 ms | 12152 KB | Output is correct |
8 | Correct | 15 ms | 12152 KB | Output is correct |
9 | Correct | 15 ms | 12024 KB | Output is correct |
10 | Correct | 16 ms | 11896 KB | Output is correct |
11 | Correct | 14 ms | 12280 KB | Output is correct |
12 | Correct | 14 ms | 11768 KB | Output is correct |
13 | Correct | 15 ms | 12152 KB | Output is correct |
14 | Correct | 15 ms | 11896 KB | Output is correct |
15 | Correct | 15 ms | 12280 KB | Output is correct |
16 | Correct | 13 ms | 12280 KB | Output is correct |
17 | Correct | 13 ms | 11896 KB | Output is correct |
18 | Correct | 14 ms | 12280 KB | Output is correct |
19 | Correct | 14 ms | 11896 KB | Output is correct |
20 | Correct | 14 ms | 12024 KB | Output is correct |
21 | Correct | 13 ms | 12024 KB | Output is correct |
22 | Correct | 11 ms | 11512 KB | Output is correct |
23 | Correct | 11 ms | 11512 KB | Output is correct |
24 | Correct | 14 ms | 12408 KB | Output is correct |
25 | Correct | 14 ms | 12536 KB | Output is correct |
26 | Correct | 14 ms | 12536 KB | Output is correct |
27 | Correct | 12 ms | 11512 KB | Output is correct |
28 | Correct | 13 ms | 12152 KB | Output is correct |
29 | Correct | 13 ms | 12152 KB | Output is correct |
30 | Correct | 13 ms | 11768 KB | Output is correct |
31 | Correct | 13 ms | 12024 KB | Output is correct |
32 | Correct | 15 ms | 12024 KB | Output is correct |
33 | Correct | 13 ms | 12536 KB | Output is correct |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 11 ms | 11516 KB | Output is correct |
2 | Correct | 11 ms | 11516 KB | Output is correct |
3 | Correct | 12 ms | 11512 KB | Output is correct |
4 | Correct | 12 ms | 11512 KB | Output is correct |
5 | Correct | 13 ms | 11512 KB | Output is correct |
6 | Correct | 13 ms | 12152 KB | Output is correct |
7 | Correct | 14 ms | 12152 KB | Output is correct |
8 | Correct | 15 ms | 12152 KB | Output is correct |
9 | Correct | 15 ms | 12024 KB | Output is correct |
10 | Correct | 16 ms | 11896 KB | Output is correct |
11 | Correct | 14 ms | 12280 KB | Output is correct |
12 | Correct | 14 ms | 11768 KB | Output is correct |
13 | Correct | 15 ms | 12152 KB | Output is correct |
14 | Correct | 15 ms | 11896 KB | Output is correct |
15 | Correct | 15 ms | 12280 KB | Output is correct |
16 | Correct | 13 ms | 12280 KB | Output is correct |
17 | Correct | 13 ms | 11896 KB | Output is correct |
18 | Correct | 14 ms | 12280 KB | Output is correct |
19 | Correct | 14 ms | 11896 KB | Output is correct |
20 | Correct | 14 ms | 12024 KB | Output is correct |
21 | Correct | 13 ms | 12024 KB | Output is correct |
22 | Correct | 11 ms | 11512 KB | Output is correct |
23 | Correct | 11 ms | 11512 KB | Output is correct |
24 | Correct | 14 ms | 12408 KB | Output is correct |
25 | Correct | 14 ms | 12536 KB | Output is correct |
26 | Correct | 14 ms | 12536 KB | Output is correct |
27 | Correct | 12 ms | 11512 KB | Output is correct |
28 | Correct | 13 ms | 12152 KB | Output is correct |
29 | Correct | 13 ms | 12152 KB | Output is correct |
30 | Correct | 13 ms | 11768 KB | Output is correct |
31 | Correct | 13 ms | 12024 KB | Output is correct |
32 | Correct | 15 ms | 12024 KB | Output is correct |
33 | Correct | 94 ms | 54120 KB | Output is correct |
34 | Correct | 94 ms | 54120 KB | Output is correct |
35 | Correct | 13 ms | 12536 KB | Output is correct |
36 | Correct | 88 ms | 37352 KB | Output is correct |
37 | Correct | 90 ms | 37356 KB | Output is correct |
38 | Correct | 142 ms | 24800 KB | Output is correct |
39 | Correct | 95 ms | 39280 KB | Output is correct |
40 | Correct | 185 ms | 36928 KB | Output is correct |
41 | Correct | 150 ms | 24964 KB | Output is correct |
42 | Correct | 95 ms | 39148 KB | Output is correct |
43 | Correct | 264 ms | 32208 KB | Output is correct |
44 | Correct | 101 ms | 44392 KB | Output is correct |
45 | Correct | 107 ms | 30952 KB | Output is correct |
46 | Correct | 105 ms | 29668 KB | Output is correct |
47 | Correct | 105 ms | 29412 KB | Output is correct |
48 | Correct | 104 ms | 29668 KB | Output is correct |
49 | Correct | 113 ms | 29924 KB | Output is correct |
50 | Correct | 101 ms | 29540 KB | Output is correct |
51 | Correct | 136 ms | 54740 KB | Output is correct |
52 | Correct | 151 ms | 55020 KB | Output is correct |
53 | Correct | 121 ms | 54892 KB | Output is correct |
54 | Correct | 100 ms | 37736 KB | Output is correct |
55 | Correct | 97 ms | 37736 KB | Output is correct |
56 | Correct | 102 ms | 38944 KB | Output is correct |
57 | Correct | 177 ms | 34028 KB | Output is correct |
58 | Correct | 130 ms | 24292 KB | Output is correct |
59 | Correct | 129 ms | 32488 KB | Output is correct |
60 | Correct | 174 ms | 26480 KB | Output is correct |
61 | Correct | 146 ms | 39916 KB | Output is correct |
62 | Correct | 283 ms | 31212 KB | Output is correct |
63 | Correct | 129 ms | 44268 KB | Output is correct |
64 | Correct | 117 ms | 31080 KB | Output is correct |
65 | Correct | 117 ms | 29940 KB | Output is correct |
66 | Correct | 118 ms | 29420 KB | Output is correct |
67 | Correct | 130 ms | 30056 KB | Output is correct |
68 | Correct | 136 ms | 30436 KB | Output is correct |
69 | Correct | 121 ms | 29168 KB | Output is correct |
70 | Correct | 114 ms | 25072 KB | Output is correct |
71 | Correct | 148 ms | 41200 KB | Output is correct |