10802 | 2024-04-14 11:48:20 | Ablablabla | Vállalati ügyelet | cpp17 | Accepted 100/100 | 587ms | 155764 KiB |
#include <bits/stdc++.h>
using namespace std;
vector<int> ans;
vector<set<int>> lefed;
vector<vector<int>> csucsok;
vector<int> vallal;
void dfs(int akt, int elozo){
int maxi = 1;
lefed[akt].insert(vallal[akt]);
for(int x : csucsok[akt]){
assert(x != elozo);
dfs(x, akt);
maxi = max(maxi, ans[x]);
if(lefed[akt].size() < lefed[x].size()){
swap(lefed[akt], lefed[x]);
}
for(int y : lefed[x]){
lefed[akt].insert(y);
}
}
while(lefed[akt].count(maxi) > 0){
maxi++;
}
ans[akt] = maxi;
}
int main()
{
int n;
cin >> n;
vector<int> szulo(n);
for(int &x : szulo){
cin >> x;
x--;
}
csucsok.assign(n, vector<int>());
for(int i = 1; i < n; i++){
csucsok[szulo[i]].push_back(i);
}
vallal.assign(n, 0);
for(int &x : vallal){
cin >> x;
}
ans.assign(n, 1);
lefed.assign(n, set<int>());
dfs(0, -1);
for(int x : ans){
cout << x << " ";
}
cout << "\n";
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1808 KiB | ||||
2 | Accepted | 314ms | 99064 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 3ms | 2384 KiB | ||||
4 | Accepted | 3ms | 2480 KiB | ||||
5 | Accepted | 3ms | 2636 KiB | ||||
6 | Accepted | 3ms | 2872 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 3ms | 2384 KiB | ||||
8 | Accepted | 3ms | 2480 KiB | ||||
9 | Accepted | 3ms | 2636 KiB | ||||
10 | Accepted | 3ms | 2872 KiB | ||||
11 | Accepted | 184ms | 57120 KiB | ||||
12 | Accepted | 194ms | 58148 KiB | ||||
13 | Accepted | 211ms | 58972 KiB | ||||
14 | Accepted | 303ms | 75348 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 3ms | 2384 KiB | ||||
16 | Accepted | 3ms | 2480 KiB | ||||
17 | Accepted | 3ms | 2636 KiB | ||||
18 | Accepted | 3ms | 2872 KiB | ||||
19 | Accepted | 256ms | 112236 KiB | ||||
20 | Accepted | 263ms | 113232 KiB | ||||
21 | Accepted | 270ms | 114344 KiB | ||||
22 | Accepted | 358ms | 130256 KiB | ||||
23 | Accepted | 326ms | 130428 KiB | ||||
24 | Accepted | 284ms | 121040 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 3ms | 2384 KiB | ||||
26 | Accepted | 3ms | 2480 KiB | ||||
27 | Accepted | 3ms | 2636 KiB | ||||
28 | Accepted | 3ms | 2872 KiB | ||||
29 | Accepted | 4ms | 4520 KiB | ||||
30 | Accepted | 4ms | 5044 KiB | ||||
31 | Accepted | 4ms | 5040 KiB | ||||
32 | Accepted | 6ms | 5064 KiB | ||||
33 | Accepted | 6ms | 5084 KiB | ||||
34 | Accepted | 4ms | 4648 KiB | ||||
35 | Accepted | 6ms | 5420 KiB | ||||
36 | Accepted | 4ms | 5104 KiB | ||||
37 | Accepted | 6ms | 5356 KiB | ||||
38 | Accepted | 6ms | 5340 KiB | ||||
39 | Accepted | 4ms | 5260 KiB | ||||
40 | Accepted | 6ms | 5396 KiB | ||||
41 | Accepted | 4ms | 5640 KiB | ||||
subtask6 | 28/28 | ||||||
42 | Accepted | 409ms | 120712 KiB | ||||
43 | Accepted | 367ms | 109276 KiB | ||||
44 | Accepted | 337ms | 109512 KiB | ||||
45 | Accepted | 335ms | 115488 KiB | ||||
46 | Accepted | 338ms | 122412 KiB | ||||
47 | Accepted | 314ms | 128352 KiB | ||||
48 | Accepted | 324ms | 77076 KiB | ||||
49 | Accepted | 356ms | 131460 KiB | ||||
50 | Accepted | 326ms | 131592 KiB | ||||
subtask7 | 30/30 | ||||||
51 | Accepted | 3ms | 5056 KiB | ||||
52 | Accepted | 314ms | 101840 KiB | ||||
53 | Accepted | 3ms | 2384 KiB | ||||
54 | Accepted | 3ms | 2480 KiB | ||||
55 | Accepted | 3ms | 2636 KiB | ||||
56 | Accepted | 3ms | 2872 KiB | ||||
57 | Accepted | 184ms | 57120 KiB | ||||
58 | Accepted | 194ms | 58148 KiB | ||||
59 | Accepted | 211ms | 58972 KiB | ||||
60 | Accepted | 303ms | 75348 KiB | ||||
61 | Accepted | 256ms | 112236 KiB | ||||
62 | Accepted | 263ms | 113232 KiB | ||||
63 | Accepted | 270ms | 114344 KiB | ||||
64 | Accepted | 358ms | 130256 KiB | ||||
65 | Accepted | 326ms | 130428 KiB | ||||
66 | Accepted | 284ms | 121040 KiB | ||||
67 | Accepted | 4ms | 4520 KiB | ||||
68 | Accepted | 4ms | 5044 KiB | ||||
69 | Accepted | 4ms | 5040 KiB | ||||
70 | Accepted | 6ms | 5064 KiB | ||||
71 | Accepted | 6ms | 5084 KiB | ||||
72 | Accepted | 4ms | 4648 KiB | ||||
73 | Accepted | 6ms | 5420 KiB | ||||
74 | Accepted | 4ms | 5104 KiB | ||||
75 | Accepted | 6ms | 5356 KiB | ||||
76 | Accepted | 6ms | 5340 KiB | ||||
77 | Accepted | 4ms | 5260 KiB | ||||
78 | Accepted | 6ms | 5396 KiB | ||||
79 | Accepted | 4ms | 5640 KiB | ||||
80 | Accepted | 409ms | 120712 KiB | ||||
81 | Accepted | 367ms | 109276 KiB | ||||
82 | Accepted | 337ms | 109512 KiB | ||||
83 | Accepted | 335ms | 115488 KiB | ||||
84 | Accepted | 338ms | 122412 KiB | ||||
85 | Accepted | 314ms | 128352 KiB | ||||
86 | Accepted | 324ms | 77076 KiB | ||||
87 | Accepted | 356ms | 131460 KiB | ||||
88 | Accepted | 326ms | 131592 KiB | ||||
89 | Accepted | 365ms | 96632 KiB | ||||
90 | Accepted | 361ms | 103472 KiB | ||||
91 | Accepted | 587ms | 143808 KiB | ||||
92 | Accepted | 546ms | 155764 KiB | ||||
93 | Accepted | 314ms | 102608 KiB | ||||
94 | Accepted | 365ms | 114800 KiB | ||||
95 | Accepted | 349ms | 127332 KiB | ||||
96 | Accepted | 331ms | 98836 KiB | ||||
97 | Accepted | 293ms | 98340 KiB | ||||
98 | Accepted | 296ms | 99724 KiB | ||||
99 | Accepted | 342ms | 107816 KiB | ||||
100 | Accepted | 321ms | 101844 KiB | ||||
101 | Accepted | 305ms | 107548 KiB |