10837 | 2024-04-16 12:31:03 | TomaSajt | Vállalati ügyelet | cpp17 | Accepted 100/100 | 439ms | 158440 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
vector<vector<int>> g;
vector<set<int>> sets;
vector<int> vals, mexes;
void dfs(int u) {
sets[u].insert(vals[u]);
for (int v : g[u]) {
dfs(v);
mexes[u] = max(mexes[u], mexes[v]);
if (sets[u].size() < sets[v].size()) swap(sets[u], sets[v]);
sets[u].insert(sets[v].begin(), sets[v].end());
}
auto it = sets[u].lower_bound(mexes[u]);
while (it != 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);
sets.resize(n + 1);
mexes.resize(n + 1, 1);
vals.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 >> vals[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 | Accepted | 215ms | 101272 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 3ms | 2412 KiB | ||||
4 | Accepted | 3ms | 2624 KiB | ||||
5 | Accepted | 3ms | 2740 KiB | ||||
6 | Accepted | 3ms | 2812 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 3ms | 2412 KiB | ||||
8 | Accepted | 3ms | 2624 KiB | ||||
9 | Accepted | 3ms | 2740 KiB | ||||
10 | Accepted | 3ms | 2812 KiB | ||||
11 | Accepted | 130ms | 59876 KiB | ||||
12 | Accepted | 141ms | 61328 KiB | ||||
13 | Accepted | 149ms | 62196 KiB | ||||
14 | Accepted | 222ms | 78076 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 3ms | 2412 KiB | ||||
16 | Accepted | 3ms | 2624 KiB | ||||
17 | Accepted | 3ms | 2740 KiB | ||||
18 | Accepted | 3ms | 2812 KiB | ||||
19 | Accepted | 167ms | 107080 KiB | ||||
20 | Accepted | 167ms | 108316 KiB | ||||
21 | Accepted | 172ms | 109320 KiB | ||||
22 | Accepted | 245ms | 125296 KiB | ||||
23 | Accepted | 212ms | 125284 KiB | ||||
24 | Accepted | 188ms | 116036 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 3ms | 2412 KiB | ||||
26 | Accepted | 3ms | 2624 KiB | ||||
27 | Accepted | 3ms | 2740 KiB | ||||
28 | Accepted | 3ms | 2812 KiB | ||||
29 | Accepted | 4ms | 4608 KiB | ||||
30 | Accepted | 4ms | 5304 KiB | ||||
31 | Accepted | 4ms | 5292 KiB | ||||
32 | Accepted | 4ms | 5184 KiB | ||||
33 | Accepted | 4ms | 5500 KiB | ||||
34 | Accepted | 4ms | 5180 KiB | ||||
35 | Accepted | 4ms | 5576 KiB | ||||
36 | Accepted | 4ms | 5260 KiB | ||||
37 | Accepted | 4ms | 5640 KiB | ||||
38 | Accepted | 4ms | 5540 KiB | ||||
39 | Accepted | 4ms | 5200 KiB | ||||
40 | Accepted | 4ms | 5448 KiB | ||||
41 | Accepted | 4ms | 5644 KiB | ||||
subtask6 | 28/28 | ||||||
42 | Accepted | 298ms | 122920 KiB | ||||
43 | Accepted | 229ms | 110540 KiB | ||||
44 | Accepted | 230ms | 109740 KiB | ||||
45 | Accepted | 211ms | 114396 KiB | ||||
46 | Accepted | 206ms | 119572 KiB | ||||
47 | Accepted | 196ms | 124360 KiB | ||||
48 | Accepted | 223ms | 79564 KiB | ||||
49 | Accepted | 229ms | 126812 KiB | ||||
50 | Accepted | 196ms | 126788 KiB | ||||
subtask7 | 30/30 | ||||||
51 | Accepted | 3ms | 4832 KiB | ||||
52 | Accepted | 215ms | 103932 KiB | ||||
53 | Accepted | 3ms | 2412 KiB | ||||
54 | Accepted | 3ms | 2624 KiB | ||||
55 | Accepted | 3ms | 2740 KiB | ||||
56 | Accepted | 3ms | 2812 KiB | ||||
57 | Accepted | 130ms | 59876 KiB | ||||
58 | Accepted | 141ms | 61328 KiB | ||||
59 | Accepted | 149ms | 62196 KiB | ||||
60 | Accepted | 222ms | 78076 KiB | ||||
61 | Accepted | 167ms | 107080 KiB | ||||
62 | Accepted | 167ms | 108316 KiB | ||||
63 | Accepted | 172ms | 109320 KiB | ||||
64 | Accepted | 245ms | 125296 KiB | ||||
65 | Accepted | 212ms | 125284 KiB | ||||
66 | Accepted | 188ms | 116036 KiB | ||||
67 | Accepted | 4ms | 4608 KiB | ||||
68 | Accepted | 4ms | 5304 KiB | ||||
69 | Accepted | 4ms | 5292 KiB | ||||
70 | Accepted | 4ms | 5184 KiB | ||||
71 | Accepted | 4ms | 5500 KiB | ||||
72 | Accepted | 4ms | 5180 KiB | ||||
73 | Accepted | 4ms | 5576 KiB | ||||
74 | Accepted | 4ms | 5260 KiB | ||||
75 | Accepted | 4ms | 5640 KiB | ||||
76 | Accepted | 4ms | 5540 KiB | ||||
77 | Accepted | 4ms | 5200 KiB | ||||
78 | Accepted | 4ms | 5448 KiB | ||||
79 | Accepted | 4ms | 5644 KiB | ||||
80 | Accepted | 298ms | 122920 KiB | ||||
81 | Accepted | 229ms | 110540 KiB | ||||
82 | Accepted | 230ms | 109740 KiB | ||||
83 | Accepted | 211ms | 114396 KiB | ||||
84 | Accepted | 206ms | 119572 KiB | ||||
85 | Accepted | 196ms | 124360 KiB | ||||
86 | Accepted | 223ms | 79564 KiB | ||||
87 | Accepted | 229ms | 126812 KiB | ||||
88 | Accepted | 196ms | 126788 KiB | ||||
89 | Accepted | 270ms | 99284 KiB | ||||
90 | Accepted | 291ms | 106168 KiB | ||||
91 | Accepted | 409ms | 146404 KiB | ||||
92 | Accepted | 439ms | 158440 KiB | ||||
93 | Accepted | 214ms | 102976 KiB | ||||
94 | Accepted | 222ms | 113648 KiB | ||||
95 | Accepted | 229ms | 124280 KiB | ||||
96 | Accepted | 210ms | 100920 KiB | ||||
97 | Accepted | 199ms | 100308 KiB | ||||
98 | Accepted | 190ms | 100616 KiB | ||||
99 | Accepted | 233ms | 110052 KiB | ||||
100 | Accepted | 221ms | 103336 KiB | ||||
101 | Accepted | 195ms | 107392 KiB |