10956 | 2024-04-20 18:42:20 | 42 | Vállalati ügyelet | pypy3 | Time limit exceeded 70/100 | 1.082s | 254132 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)-1000:
#A[P[i]]=A[P[i]].union(cur)
A[P[i]] |= cur
else:
A[P[i]] = cur.union(A[P[i]])
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 | 76352 KiB | ||||
2 | Accepted | 270ms | 181768 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 39ms | 76436 KiB | ||||
4 | Accepted | 46ms | 76840 KiB | ||||
5 | Accepted | 43ms | 77376 KiB | ||||
6 | Accepted | 46ms | 78184 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 39ms | 76436 KiB | ||||
8 | Accepted | 46ms | 76840 KiB | ||||
9 | Accepted | 43ms | 77376 KiB | ||||
10 | Accepted | 46ms | 78184 KiB | ||||
11 | Accepted | 184ms | 177500 KiB | ||||
12 | Accepted | 186ms | 177216 KiB | ||||
13 | Accepted | 188ms | 177788 KiB | ||||
14 | Accepted | 217ms | 180700 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 39ms | 76436 KiB | ||||
16 | Accepted | 46ms | 76840 KiB | ||||
17 | Accepted | 43ms | 77376 KiB | ||||
18 | Accepted | 46ms | 78184 KiB | ||||
19 | Accepted | 172ms | 183284 KiB | ||||
20 | Accepted | 201ms | 178568 KiB | ||||
21 | Accepted | 178ms | 179664 KiB | ||||
22 | Accepted | 201ms | 185004 KiB | ||||
23 | Accepted | 197ms | 182296 KiB | ||||
24 | Accepted | 192ms | 179916 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 39ms | 76436 KiB | ||||
26 | Accepted | 46ms | 76840 KiB | ||||
27 | Accepted | 43ms | 77376 KiB | ||||
28 | Accepted | 46ms | 78184 KiB | ||||
29 | Accepted | 71ms | 91520 KiB | ||||
30 | Accepted | 67ms | 91112 KiB | ||||
31 | Accepted | 68ms | 91200 KiB | ||||
32 | Accepted | 72ms | 91384 KiB | ||||
33 | Accepted | 70ms | 91500 KiB | ||||
34 | Accepted | 64ms | 92216 KiB | ||||
35 | Accepted | 65ms | 91804 KiB | ||||
36 | Accepted | 71ms | 92468 KiB | ||||
37 | Accepted | 65ms | 92308 KiB | ||||
38 | Accepted | 64ms | 92292 KiB | ||||
39 | Accepted | 79ms | 92972 KiB | ||||
40 | Accepted | 68ms | 92900 KiB | ||||
41 | Accepted | 64ms | 92788 KiB | ||||
subtask6 | 28/28 | ||||||
42 | Accepted | 291ms | 180716 KiB | ||||
43 | Accepted | 381ms | 184644 KiB | ||||
44 | Accepted | 477ms | 184448 KiB | ||||
45 | Accepted | 418ms | 184472 KiB | ||||
46 | Accepted | 342ms | 183652 KiB | ||||
47 | Accepted | 237ms | 183620 KiB | ||||
48 | Accepted | 221ms | 182696 KiB | ||||
49 | Accepted | 202ms | 186688 KiB | ||||
50 | Accepted | 197ms | 183768 KiB | ||||
subtask7 | 0/30 | ||||||
51 | Accepted | 39ms | 81120 KiB | ||||
52 | Accepted | 294ms | 185876 KiB | ||||
53 | Accepted | 39ms | 76436 KiB | ||||
54 | Accepted | 46ms | 76840 KiB | ||||
55 | Accepted | 43ms | 77376 KiB | ||||
56 | Accepted | 46ms | 78184 KiB | ||||
57 | Accepted | 184ms | 177500 KiB | ||||
58 | Accepted | 186ms | 177216 KiB | ||||
59 | Accepted | 188ms | 177788 KiB | ||||
60 | Accepted | 217ms | 180700 KiB | ||||
61 | Accepted | 172ms | 183284 KiB | ||||
62 | Accepted | 201ms | 178568 KiB | ||||
63 | Accepted | 178ms | 179664 KiB | ||||
64 | Accepted | 201ms | 185004 KiB | ||||
65 | Accepted | 197ms | 182296 KiB | ||||
66 | Accepted | 192ms | 179916 KiB | ||||
67 | Accepted | 71ms | 91520 KiB | ||||
68 | Accepted | 67ms | 91112 KiB | ||||
69 | Accepted | 68ms | 91200 KiB | ||||
70 | Accepted | 72ms | 91384 KiB | ||||
71 | Accepted | 70ms | 91500 KiB | ||||
72 | Accepted | 64ms | 92216 KiB | ||||
73 | Accepted | 65ms | 91804 KiB | ||||
74 | Accepted | 71ms | 92468 KiB | ||||
75 | Accepted | 65ms | 92308 KiB | ||||
76 | Accepted | 64ms | 92292 KiB | ||||
77 | Accepted | 79ms | 92972 KiB | ||||
78 | Accepted | 68ms | 92900 KiB | ||||
79 | Accepted | 64ms | 92788 KiB | ||||
80 | Accepted | 291ms | 180716 KiB | ||||
81 | Accepted | 381ms | 184644 KiB | ||||
82 | Accepted | 477ms | 184448 KiB | ||||
83 | Accepted | 418ms | 184472 KiB | ||||
84 | Accepted | 342ms | 183652 KiB | ||||
85 | Accepted | 237ms | 183620 KiB | ||||
86 | Accepted | 221ms | 182696 KiB | ||||
87 | Accepted | 202ms | 186688 KiB | ||||
88 | Accepted | 197ms | 183768 KiB | ||||
89 | Accepted | 349ms | 193720 KiB | ||||
90 | Accepted | 428ms | 205260 KiB | ||||
91 | Accepted | 409ms | 237400 KiB | ||||
92 | Accepted | 428ms | 254132 KiB | ||||
93 | Time limit exceeded | 1.046s | 87984 KiB | ||||
94 | Time limit exceeded | 1.082s | 90264 KiB | ||||
95 | Accepted | 248ms | 188300 KiB | ||||
96 | Accepted | 472ms | 218908 KiB | ||||
97 | Accepted | 277ms | 186372 KiB | ||||
98 | Accepted | 254ms | 181536 KiB | ||||
99 | Accepted | 282ms | 180324 KiB | ||||
100 | Accepted | 331ms | 180316 KiB | ||||
101 | Accepted | 263ms | 186384 KiB |