10923 | 2024-04-19 11:36:36 | k_balint | Vállalati ügyelet | cpp17 | Accepted 100/100 | 509ms | 160660 KiB |
#include <bits/stdc++.h>
using namespace std;
const int c=2e5+5;
int n;
vector<int> adj[c];
int arr[c], ans[c];
set<int> s[c];
void dfs(int v, int p){
for(int x:adj[v]){
if(x != p) dfs(x,v);
}
s[v].insert(arr[v]);
ans[v]=1;
for(int x:adj[v]){
if(x==p) continue;
ans[v]=max(ans[v],ans[x]);
if(s[x].size() > s[v].size()) swap(s[x],s[v]);
for(int y:s[x]) s[v].insert(y);
}
while(s[v].find(ans[v]) != s[v].end()) ++ans[v];
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
int p; cin>>p;
if(p != 0){
adj[i].push_back(p);
adj[p].push_back(i);
}
}
for(int i=1;i<=n;i++) cin>>arr[i];
dfs(1,0);
for(int i=1;i<=n;i++){
cout << ans[i] << ' ';
}
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 13ms | 30048 KiB | ||||
2 | Accepted | 241ms | 102988 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 13ms | 30580 KiB | ||||
4 | Accepted | 13ms | 30908 KiB | ||||
5 | Accepted | 13ms | 30864 KiB | ||||
6 | Accepted | 14ms | 31196 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 13ms | 30580 KiB | ||||
8 | Accepted | 13ms | 30908 KiB | ||||
9 | Accepted | 13ms | 30864 KiB | ||||
10 | Accepted | 14ms | 31196 KiB | ||||
11 | Accepted | 127ms | 68024 KiB | ||||
12 | Accepted | 143ms | 69016 KiB | ||||
13 | Accepted | 143ms | 69860 KiB | ||||
14 | Accepted | 240ms | 86020 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 13ms | 30580 KiB | ||||
16 | Accepted | 13ms | 30908 KiB | ||||
17 | Accepted | 13ms | 30864 KiB | ||||
18 | Accepted | 14ms | 31196 KiB | ||||
19 | Accepted | 192ms | 116924 KiB | ||||
20 | Accepted | 204ms | 118088 KiB | ||||
21 | Accepted | 210ms | 119020 KiB | ||||
22 | Accepted | 310ms | 135184 KiB | ||||
23 | Accepted | 231ms | 135196 KiB | ||||
24 | Accepted | 202ms | 125804 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 13ms | 30580 KiB | ||||
26 | Accepted | 13ms | 30908 KiB | ||||
27 | Accepted | 13ms | 30864 KiB | ||||
28 | Accepted | 14ms | 31196 KiB | ||||
29 | Accepted | 14ms | 32344 KiB | ||||
30 | Accepted | 14ms | 32836 KiB | ||||
31 | Accepted | 14ms | 32840 KiB | ||||
32 | Accepted | 14ms | 32608 KiB | ||||
33 | Accepted | 17ms | 32908 KiB | ||||
34 | Accepted | 14ms | 32600 KiB | ||||
35 | Accepted | 14ms | 33084 KiB | ||||
36 | Accepted | 17ms | 33136 KiB | ||||
37 | Accepted | 16ms | 33368 KiB | ||||
38 | Accepted | 14ms | 33172 KiB | ||||
39 | Accepted | 17ms | 33356 KiB | ||||
40 | Accepted | 16ms | 33492 KiB | ||||
41 | Accepted | 14ms | 33424 KiB | ||||
subtask6 | 28/28 | ||||||
42 | Accepted | 324ms | 125472 KiB | ||||
43 | Accepted | 287ms | 114312 KiB | ||||
44 | Accepted | 247ms | 115264 KiB | ||||
45 | Accepted | 245ms | 121624 KiB | ||||
46 | Accepted | 238ms | 128080 KiB | ||||
47 | Accepted | 241ms | 133596 KiB | ||||
48 | Accepted | 214ms | 87568 KiB | ||||
49 | Accepted | 358ms | 136172 KiB | ||||
50 | Accepted | 233ms | 136088 KiB | ||||
subtask7 | 30/30 | ||||||
51 | Accepted | 13ms | 32756 KiB | ||||
52 | Accepted | 240ms | 105428 KiB | ||||
53 | Accepted | 13ms | 30580 KiB | ||||
54 | Accepted | 13ms | 30908 KiB | ||||
55 | Accepted | 13ms | 30864 KiB | ||||
56 | Accepted | 14ms | 31196 KiB | ||||
57 | Accepted | 127ms | 68024 KiB | ||||
58 | Accepted | 143ms | 69016 KiB | ||||
59 | Accepted | 143ms | 69860 KiB | ||||
60 | Accepted | 240ms | 86020 KiB | ||||
61 | Accepted | 192ms | 116924 KiB | ||||
62 | Accepted | 204ms | 118088 KiB | ||||
63 | Accepted | 210ms | 119020 KiB | ||||
64 | Accepted | 310ms | 135184 KiB | ||||
65 | Accepted | 231ms | 135196 KiB | ||||
66 | Accepted | 202ms | 125804 KiB | ||||
67 | Accepted | 14ms | 32344 KiB | ||||
68 | Accepted | 14ms | 32836 KiB | ||||
69 | Accepted | 14ms | 32840 KiB | ||||
70 | Accepted | 14ms | 32608 KiB | ||||
71 | Accepted | 17ms | 32908 KiB | ||||
72 | Accepted | 14ms | 32600 KiB | ||||
73 | Accepted | 14ms | 33084 KiB | ||||
74 | Accepted | 17ms | 33136 KiB | ||||
75 | Accepted | 16ms | 33368 KiB | ||||
76 | Accepted | 14ms | 33172 KiB | ||||
77 | Accepted | 17ms | 33356 KiB | ||||
78 | Accepted | 16ms | 33492 KiB | ||||
79 | Accepted | 14ms | 33424 KiB | ||||
80 | Accepted | 324ms | 125472 KiB | ||||
81 | Accepted | 287ms | 114312 KiB | ||||
82 | Accepted | 247ms | 115264 KiB | ||||
83 | Accepted | 245ms | 121624 KiB | ||||
84 | Accepted | 238ms | 128080 KiB | ||||
85 | Accepted | 241ms | 133596 KiB | ||||
86 | Accepted | 214ms | 87568 KiB | ||||
87 | Accepted | 358ms | 136172 KiB | ||||
88 | Accepted | 233ms | 136088 KiB | ||||
89 | Accepted | 286ms | 101404 KiB | ||||
90 | Accepted | 361ms | 108496 KiB | ||||
91 | Accepted | 509ms | 148916 KiB | ||||
92 | Accepted | 472ms | 160660 KiB | ||||
93 | Accepted | 246ms | 106228 KiB | ||||
94 | Accepted | 270ms | 119128 KiB | ||||
95 | Accepted | 298ms | 131784 KiB | ||||
96 | Accepted | 239ms | 102372 KiB | ||||
97 | Accepted | 224ms | 101940 KiB | ||||
98 | Accepted | 216ms | 103340 KiB | ||||
99 | Accepted | 287ms | 112800 KiB | ||||
100 | Accepted | 233ms | 106332 KiB | ||||
101 | Accepted | 222ms | 112028 KiB |