10832 | 2024-04-16 10:27:05 | TomaSajt | Vállalati ügyelet | cpp17 | Runtime error 30/100 | 714ms | 263016 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 != subtree_sets[u].end() && *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 | 1760 KiB | ||||
2 | Runtime error | 372ms | 263016 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 3ms | 2160 KiB | ||||
4 | Accepted | 3ms | 2384 KiB | ||||
5 | Accepted | 3ms | 2464 KiB | ||||
6 | Accepted | 3ms | 2696 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 3ms | 2160 KiB | ||||
8 | Accepted | 3ms | 2384 KiB | ||||
9 | Accepted | 3ms | 2464 KiB | ||||
10 | Accepted | 3ms | 2696 KiB | ||||
11 | Accepted | 118ms | 59964 KiB | ||||
12 | Accepted | 120ms | 60928 KiB | ||||
13 | Accepted | 126ms | 62152 KiB | ||||
14 | Accepted | 186ms | 78292 KiB | ||||
subtask4 | 0/12 | ||||||
15 | Accepted | 3ms | 2160 KiB | ||||
16 | Accepted | 3ms | 2384 KiB | ||||
17 | Accepted | 3ms | 2464 KiB | ||||
18 | Accepted | 3ms | 2696 KiB | ||||
19 | Runtime error | 284ms | 261536 KiB | ||||
20 | Runtime error | 286ms | 261424 KiB | ||||
21 | Runtime error | 287ms | 261416 KiB | ||||
22 | Runtime error | 289ms | 261400 KiB | ||||
23 | Runtime error | 330ms | 261388 KiB | ||||
24 | Runtime error | 321ms | 261160 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 3ms | 2160 KiB | ||||
26 | Accepted | 3ms | 2384 KiB | ||||
27 | Accepted | 3ms | 2464 KiB | ||||
28 | Accepted | 3ms | 2696 KiB | ||||
29 | Accepted | 4ms | 4644 KiB | ||||
30 | Accepted | 314ms | 192440 KiB | ||||
31 | Accepted | 356ms | 192444 KiB | ||||
32 | Accepted | 46ms | 27508 KiB | ||||
33 | Accepted | 137ms | 75868 KiB | ||||
34 | Accepted | 4ms | 4848 KiB | ||||
35 | Accepted | 6ms | 5828 KiB | ||||
36 | Accepted | 32ms | 21520 KiB | ||||
37 | Accepted | 182ms | 113848 KiB | ||||
38 | Accepted | 10ms | 9424 KiB | ||||
39 | Accepted | 17ms | 13708 KiB | ||||
40 | Accepted | 13ms | 10340 KiB | ||||
41 | Accepted | 70ms | 41964 KiB | ||||
subtask6 | 0/28 | ||||||
42 | Runtime error | 453ms | 260828 KiB | ||||
43 | Runtime error | 389ms | 260820 KiB | ||||
44 | Runtime error | 370ms | 260804 KiB | ||||
45 | Runtime error | 354ms | 260800 KiB | ||||
46 | Runtime error | 342ms | 260792 KiB | ||||
47 | Runtime error | 333ms | 260796 KiB | ||||
48 | Accepted | 199ms | 79436 KiB | ||||
49 | Runtime error | 287ms | 260560 KiB | ||||
50 | Runtime error | 328ms | 260560 KiB | ||||
subtask7 | 0/30 | ||||||
51 | Accepted | 3ms | 4480 KiB | ||||
52 | Runtime error | 360ms | 260536 KiB | ||||
53 | Accepted | 3ms | 2160 KiB | ||||
54 | Accepted | 3ms | 2384 KiB | ||||
55 | Accepted | 3ms | 2464 KiB | ||||
56 | Accepted | 3ms | 2696 KiB | ||||
57 | Accepted | 118ms | 59964 KiB | ||||
58 | Accepted | 120ms | 60928 KiB | ||||
59 | Accepted | 126ms | 62152 KiB | ||||
60 | Accepted | 186ms | 78292 KiB | ||||
61 | Runtime error | 284ms | 261536 KiB | ||||
62 | Runtime error | 286ms | 261424 KiB | ||||
63 | Runtime error | 287ms | 261416 KiB | ||||
64 | Runtime error | 289ms | 261400 KiB | ||||
65 | Runtime error | 330ms | 261388 KiB | ||||
66 | Runtime error | 321ms | 261160 KiB | ||||
67 | Accepted | 4ms | 4644 KiB | ||||
68 | Accepted | 314ms | 192440 KiB | ||||
69 | Accepted | 356ms | 192444 KiB | ||||
70 | Accepted | 46ms | 27508 KiB | ||||
71 | Accepted | 137ms | 75868 KiB | ||||
72 | Accepted | 4ms | 4848 KiB | ||||
73 | Accepted | 6ms | 5828 KiB | ||||
74 | Accepted | 32ms | 21520 KiB | ||||
75 | Accepted | 182ms | 113848 KiB | ||||
76 | Accepted | 10ms | 9424 KiB | ||||
77 | Accepted | 17ms | 13708 KiB | ||||
78 | Accepted | 13ms | 10340 KiB | ||||
79 | Accepted | 70ms | 41964 KiB | ||||
80 | Runtime error | 453ms | 260828 KiB | ||||
81 | Runtime error | 389ms | 260820 KiB | ||||
82 | Runtime error | 370ms | 260804 KiB | ||||
83 | Runtime error | 354ms | 260800 KiB | ||||
84 | Runtime error | 342ms | 260792 KiB | ||||
85 | Runtime error | 333ms | 260796 KiB | ||||
86 | Accepted | 199ms | 79436 KiB | ||||
87 | Runtime error | 287ms | 260560 KiB | ||||
88 | Runtime error | 328ms | 260560 KiB | ||||
89 | Accepted | 358ms | 146284 KiB | ||||
90 | Accepted | 472ms | 162684 KiB | ||||
91 | Accepted | 714ms | 254692 KiB | ||||
92 | Runtime error | 497ms | 260552 KiB | ||||
93 | Runtime error | 381ms | 260544 KiB | ||||
94 | Runtime error | 382ms | 260536 KiB | ||||
95 | Runtime error | 381ms | 260524 KiB | ||||
96 | Runtime error | 388ms | 260496 KiB | ||||
97 | Runtime error | 361ms | 260496 KiB | ||||
98 | Runtime error | 342ms | 260504 KiB | ||||
99 | Runtime error | 407ms | 260504 KiB | ||||
100 | Runtime error | 381ms | 260276 KiB | ||||
101 | Runtime error | 345ms | 260280 KiB |