10958 | 2024-04-20 18:48:24 | 42 | Vállalati ügyelet | pypy3 | Accepted 100/100 | 418ms | 260216 KiB |
from sys import stdin, stdout
input=stdin.readline
def main():
N = int(input())
P = [0]+list(map(int, input().split()))
A = [0]+list(map(int, input().split()))
res=[1]*(N+1)
for i in range(N,0,-1):
cur=A.pop()
if isinstance(cur,int):
cur={cur}
while res[i] in cur:
cur.remove(res[i])
res[i]+=1
res[P[i]]=max(res[i],res[P[i]])
if isinstance(A[P[i]],int):
cur.add(A[P[i]])
A[P[i]]=cur
else:
if len(A[P[i]]) >= len(cur)-100:
A[P[i]].update(cur)
#A[P[i]]=A[P[i]].union(cur)
#A[P[i]] |= cur
else:
cur.update(A[P[i]])
A[P[i]] = cur
for i in range(1,N+1):
stdout.write(str(res[i])+' ')
stdout.write('\n')
main()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 39ms | 76660 KiB | ||||
2 | Accepted | 259ms | 181644 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 41ms | 76844 KiB | ||||
4 | Accepted | 48ms | 77040 KiB | ||||
5 | Accepted | 43ms | 77836 KiB | ||||
6 | Accepted | 39ms | 78260 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 41ms | 76844 KiB | ||||
8 | Accepted | 48ms | 77040 KiB | ||||
9 | Accepted | 43ms | 77836 KiB | ||||
10 | Accepted | 39ms | 78260 KiB | ||||
11 | Accepted | 180ms | 177364 KiB | ||||
12 | Accepted | 216ms | 177188 KiB | ||||
13 | Accepted | 189ms | 176848 KiB | ||||
14 | Accepted | 250ms | 180052 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 41ms | 76844 KiB | ||||
16 | Accepted | 48ms | 77040 KiB | ||||
17 | Accepted | 43ms | 77836 KiB | ||||
18 | Accepted | 39ms | 78260 KiB | ||||
19 | Accepted | 173ms | 182688 KiB | ||||
20 | Accepted | 202ms | 178164 KiB | ||||
21 | Accepted | 178ms | 179272 KiB | ||||
22 | Accepted | 201ms | 184904 KiB | ||||
23 | Accepted | 195ms | 182152 KiB | ||||
24 | Accepted | 194ms | 179452 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 41ms | 76844 KiB | ||||
26 | Accepted | 48ms | 77040 KiB | ||||
27 | Accepted | 43ms | 77836 KiB | ||||
28 | Accepted | 39ms | 78260 KiB | ||||
29 | Accepted | 64ms | 91468 KiB | ||||
30 | Accepted | 59ms | 91232 KiB | ||||
31 | Accepted | 61ms | 90976 KiB | ||||
32 | Accepted | 64ms | 91224 KiB | ||||
33 | Accepted | 65ms | 90804 KiB | ||||
34 | Accepted | 64ms | 91548 KiB | ||||
35 | Accepted | 65ms | 91668 KiB | ||||
36 | Accepted | 63ms | 91644 KiB | ||||
37 | Accepted | 61ms | 91236 KiB | ||||
38 | Accepted | 68ms | 91440 KiB | ||||
39 | Accepted | 65ms | 91508 KiB | ||||
40 | Accepted | 64ms | 91484 KiB | ||||
41 | Accepted | 63ms | 91732 KiB | ||||
subtask6 | 28/28 | ||||||
42 | Accepted | 250ms | 179656 KiB | ||||
43 | Accepted | 237ms | 183240 KiB | ||||
44 | Accepted | 233ms | 183368 KiB | ||||
45 | Accepted | 252ms | 183260 KiB | ||||
46 | Accepted | 231ms | 182476 KiB | ||||
47 | Accepted | 215ms | 182764 KiB | ||||
48 | Accepted | 215ms | 181512 KiB | ||||
49 | Accepted | 201ms | 185284 KiB | ||||
50 | Accepted | 195ms | 182588 KiB | ||||
subtask7 | 30/30 | ||||||
51 | Accepted | 39ms | 79684 KiB | ||||
52 | Accepted | 231ms | 184392 KiB | ||||
53 | Accepted | 41ms | 76844 KiB | ||||
54 | Accepted | 48ms | 77040 KiB | ||||
55 | Accepted | 43ms | 77836 KiB | ||||
56 | Accepted | 39ms | 78260 KiB | ||||
57 | Accepted | 180ms | 177364 KiB | ||||
58 | Accepted | 216ms | 177188 KiB | ||||
59 | Accepted | 189ms | 176848 KiB | ||||
60 | Accepted | 250ms | 180052 KiB | ||||
61 | Accepted | 173ms | 182688 KiB | ||||
62 | Accepted | 202ms | 178164 KiB | ||||
63 | Accepted | 178ms | 179272 KiB | ||||
64 | Accepted | 201ms | 184904 KiB | ||||
65 | Accepted | 195ms | 182152 KiB | ||||
66 | Accepted | 194ms | 179452 KiB | ||||
67 | Accepted | 64ms | 91468 KiB | ||||
68 | Accepted | 59ms | 91232 KiB | ||||
69 | Accepted | 61ms | 90976 KiB | ||||
70 | Accepted | 64ms | 91224 KiB | ||||
71 | Accepted | 65ms | 90804 KiB | ||||
72 | Accepted | 64ms | 91548 KiB | ||||
73 | Accepted | 65ms | 91668 KiB | ||||
74 | Accepted | 63ms | 91644 KiB | ||||
75 | Accepted | 61ms | 91236 KiB | ||||
76 | Accepted | 68ms | 91440 KiB | ||||
77 | Accepted | 65ms | 91508 KiB | ||||
78 | Accepted | 64ms | 91484 KiB | ||||
79 | Accepted | 63ms | 91732 KiB | ||||
80 | Accepted | 250ms | 179656 KiB | ||||
81 | Accepted | 237ms | 183240 KiB | ||||
82 | Accepted | 233ms | 183368 KiB | ||||
83 | Accepted | 252ms | 183260 KiB | ||||
84 | Accepted | 231ms | 182476 KiB | ||||
85 | Accepted | 215ms | 182764 KiB | ||||
86 | Accepted | 215ms | 181512 KiB | ||||
87 | Accepted | 201ms | 185284 KiB | ||||
88 | Accepted | 195ms | 182588 KiB | ||||
89 | Accepted | 347ms | 198836 KiB | ||||
90 | Accepted | 345ms | 196756 KiB | ||||
91 | Accepted | 395ms | 231432 KiB | ||||
92 | Accepted | 418ms | 260216 KiB | ||||
93 | Accepted | 245ms | 180868 KiB | ||||
94 | Accepted | 261ms | 182100 KiB | ||||
95 | Accepted | 231ms | 186612 KiB | ||||
96 | Accepted | 239ms | 179052 KiB | ||||
97 | Accepted | 226ms | 185064 KiB | ||||
98 | Accepted | 273ms | 180412 KiB | ||||
99 | Accepted | 268ms | 179384 KiB | ||||
100 | Accepted | 234ms | 178712 KiB | ||||
101 | Accepted | 254ms | 185032 KiB |