10831 | 2024-04-16 10:25:51 | TomaSajt | Vállalati ügyelet | cpp17 | Runtime error 30/100 | 610ms | 262860 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int>> g;
vector<set<int>> subtree_sets;
vector<int> val;
vector<int> mexes;
void dfs(int u) {
int best_v = -1;
for (int v : g[u]) {
dfs(v);
mexes[u] = max(mexes[u], mexes[v]);
if (best_v == -1 || subtree_sets[v].size() > subtree_sets[best_v].size()) v = best_v;
}
if (best_v != -1) subtree_sets[u] = subtree_sets[best_v];
subtree_sets[u].insert(val[u]);
for (int v : g[u]) {
if (v == best_v) continue;
subtree_sets[u].insert(subtree_sets[v].begin(), subtree_sets[v].end());
}
auto it = subtree_sets[u].lower_bound(mexes[u]);
while (*it == mexes[u]) mexes[u]++, it++;
}
signed main() {
ios::sync_with_stdio(0), cin.tie(0);
int n;
cin >> n;
g.resize(n + 1);
subtree_sets.resize(n + 1);
mexes.resize(n + 1, 1);
val.resize(n + 1);
for (int i = 1; i <= n; i++) {
int p;
cin >> p;
g[p].push_back(i);
}
for (int i = 1; i <= n; i++) cin >> val[i];
dfs(1);
for (int i = 1; i <= n; i++) cout << mexes[i] << ' ';
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1888 KiB | ||||
2 | Runtime error | 391ms | 262860 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 3ms | 2312 KiB | ||||
4 | Accepted | 3ms | 2532 KiB | ||||
5 | Accepted | 3ms | 2896 KiB | ||||
6 | Accepted | 3ms | 3012 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 3ms | 2312 KiB | ||||
8 | Accepted | 3ms | 2532 KiB | ||||
9 | Accepted | 3ms | 2896 KiB | ||||
10 | Accepted | 3ms | 3012 KiB | ||||
11 | Accepted | 112ms | 60360 KiB | ||||
12 | Accepted | 120ms | 61356 KiB | ||||
13 | Accepted | 126ms | 62244 KiB | ||||
14 | Accepted | 197ms | 78456 KiB | ||||
subtask4 | 0/12 | ||||||
15 | Accepted | 3ms | 2312 KiB | ||||
16 | Accepted | 3ms | 2532 KiB | ||||
17 | Accepted | 3ms | 2896 KiB | ||||
18 | Accepted | 3ms | 3012 KiB | ||||
19 | Runtime error | 284ms | 261420 KiB | ||||
20 | Runtime error | 284ms | 261184 KiB | ||||
21 | Runtime error | 286ms | 261156 KiB | ||||
22 | Runtime error | 287ms | 261144 KiB | ||||
23 | Runtime error | 328ms | 261112 KiB | ||||
24 | Runtime error | 321ms | 261124 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 3ms | 2312 KiB | ||||
26 | Accepted | 3ms | 2532 KiB | ||||
27 | Accepted | 3ms | 2896 KiB | ||||
28 | Accepted | 3ms | 3012 KiB | ||||
29 | Accepted | 4ms | 4676 KiB | ||||
30 | Accepted | 308ms | 192552 KiB | ||||
31 | Accepted | 356ms | 192532 KiB | ||||
32 | Accepted | 46ms | 27300 KiB | ||||
33 | Accepted | 138ms | 75952 KiB | ||||
34 | Accepted | 4ms | 5016 KiB | ||||
35 | Accepted | 6ms | 5996 KiB | ||||
36 | Accepted | 29ms | 21356 KiB | ||||
37 | Accepted | 201ms | 113868 KiB | ||||
38 | Accepted | 12ms | 9328 KiB | ||||
39 | Accepted | 17ms | 13696 KiB | ||||
40 | Accepted | 13ms | 10328 KiB | ||||
41 | Accepted | 70ms | 41852 KiB | ||||
subtask6 | 0/28 | ||||||
42 | Runtime error | 456ms | 260880 KiB | ||||
43 | Runtime error | 391ms | 260848 KiB | ||||
44 | Runtime error | 372ms | 260840 KiB | ||||
45 | Runtime error | 358ms | 260836 KiB | ||||
46 | Runtime error | 344ms | 260824 KiB | ||||
47 | Runtime error | 333ms | 260808 KiB | ||||
48 | Accepted | 199ms | 79212 KiB | ||||
49 | Runtime error | 289ms | 260788 KiB | ||||
50 | Runtime error | 335ms | 260788 KiB | ||||
subtask7 | 0/30 | ||||||
51 | Accepted | 3ms | 4260 KiB | ||||
52 | Runtime error | 388ms | 260788 KiB | ||||
53 | Accepted | 3ms | 2312 KiB | ||||
54 | Accepted | 3ms | 2532 KiB | ||||
55 | Accepted | 3ms | 2896 KiB | ||||
56 | Accepted | 3ms | 3012 KiB | ||||
57 | Accepted | 112ms | 60360 KiB | ||||
58 | Accepted | 120ms | 61356 KiB | ||||
59 | Accepted | 126ms | 62244 KiB | ||||
60 | Accepted | 197ms | 78456 KiB | ||||
61 | Runtime error | 284ms | 261420 KiB | ||||
62 | Runtime error | 284ms | 261184 KiB | ||||
63 | Runtime error | 286ms | 261156 KiB | ||||
64 | Runtime error | 287ms | 261144 KiB | ||||
65 | Runtime error | 328ms | 261112 KiB | ||||
66 | Runtime error | 321ms | 261124 KiB | ||||
67 | Accepted | 4ms | 4676 KiB | ||||
68 | Accepted | 308ms | 192552 KiB | ||||
69 | Accepted | 356ms | 192532 KiB | ||||
70 | Accepted | 46ms | 27300 KiB | ||||
71 | Accepted | 138ms | 75952 KiB | ||||
72 | Accepted | 4ms | 5016 KiB | ||||
73 | Accepted | 6ms | 5996 KiB | ||||
74 | Accepted | 29ms | 21356 KiB | ||||
75 | Accepted | 201ms | 113868 KiB | ||||
76 | Accepted | 12ms | 9328 KiB | ||||
77 | Accepted | 17ms | 13696 KiB | ||||
78 | Accepted | 13ms | 10328 KiB | ||||
79 | Accepted | 70ms | 41852 KiB | ||||
80 | Runtime error | 456ms | 260880 KiB | ||||
81 | Runtime error | 391ms | 260848 KiB | ||||
82 | Runtime error | 372ms | 260840 KiB | ||||
83 | Runtime error | 358ms | 260836 KiB | ||||
84 | Runtime error | 344ms | 260824 KiB | ||||
85 | Runtime error | 333ms | 260808 KiB | ||||
86 | Accepted | 199ms | 79212 KiB | ||||
87 | Runtime error | 289ms | 260788 KiB | ||||
88 | Runtime error | 335ms | 260788 KiB | ||||
89 | Accepted | 361ms | 146048 KiB | ||||
90 | Accepted | 393ms | 162528 KiB | ||||
91 | Accepted | 610ms | 254648 KiB | ||||
92 | Runtime error | 493ms | 260800 KiB | ||||
93 | Runtime error | 381ms | 260792 KiB | ||||
94 | Runtime error | 382ms | 260780 KiB | ||||
95 | Runtime error | 381ms | 260752 KiB | ||||
96 | Runtime error | 389ms | 260768 KiB | ||||
97 | Runtime error | 361ms | 260768 KiB | ||||
98 | Runtime error | 344ms | 260772 KiB | ||||
99 | Runtime error | 411ms | 260772 KiB | ||||
100 | Runtime error | 361ms | 260776 KiB | ||||
101 | Runtime error | 347ms | 260768 KiB |