10953 | 2024-04-20 18:37:17 | 42 | Vállalati ügyelet | pypy3 | Time limit exceeded 70/100 | 1.093s | 261220 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)+500:
#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 | 41ms | 76784 KiB | ||||
2 | Accepted | 275ms | 181644 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 39ms | 76840 KiB | ||||
4 | Accepted | 39ms | 77596 KiB | ||||
5 | Accepted | 39ms | 78204 KiB | ||||
6 | Accepted | 39ms | 78080 KiB | ||||
subtask3 | 8/8 | ||||||
7 | Accepted | 39ms | 76840 KiB | ||||
8 | Accepted | 39ms | 77596 KiB | ||||
9 | Accepted | 39ms | 78204 KiB | ||||
10 | Accepted | 39ms | 78080 KiB | ||||
11 | Accepted | 182ms | 176072 KiB | ||||
12 | Accepted | 193ms | 176184 KiB | ||||
13 | Accepted | 188ms | 176356 KiB | ||||
14 | Accepted | 223ms | 195800 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 39ms | 76840 KiB | ||||
16 | Accepted | 39ms | 77596 KiB | ||||
17 | Accepted | 39ms | 78204 KiB | ||||
18 | Accepted | 39ms | 78080 KiB | ||||
19 | Accepted | 171ms | 182972 KiB | ||||
20 | Accepted | 173ms | 177880 KiB | ||||
21 | Accepted | 172ms | 178980 KiB | ||||
22 | Accepted | 201ms | 184128 KiB | ||||
23 | Accepted | 222ms | 181796 KiB | ||||
24 | Accepted | 194ms | 179300 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 39ms | 76840 KiB | ||||
26 | Accepted | 39ms | 77596 KiB | ||||
27 | Accepted | 39ms | 78204 KiB | ||||
28 | Accepted | 39ms | 78080 KiB | ||||
29 | Accepted | 68ms | 91304 KiB | ||||
30 | Accepted | 59ms | 90872 KiB | ||||
31 | Accepted | 61ms | 90912 KiB | ||||
32 | Accepted | 78ms | 91180 KiB | ||||
33 | Accepted | 70ms | 91264 KiB | ||||
34 | Accepted | 64ms | 91892 KiB | ||||
35 | Accepted | 67ms | 91988 KiB | ||||
36 | Accepted | 63ms | 91204 KiB | ||||
37 | Accepted | 63ms | 91316 KiB | ||||
38 | Accepted | 64ms | 91528 KiB | ||||
39 | Accepted | 65ms | 91516 KiB | ||||
40 | Accepted | 65ms | 91852 KiB | ||||
41 | Accepted | 64ms | 91308 KiB | ||||
subtask6 | 28/28 | ||||||
42 | Accepted | 300ms | 179244 KiB | ||||
43 | Accepted | 368ms | 183376 KiB | ||||
44 | Accepted | 433ms | 183208 KiB | ||||
45 | Accepted | 386ms | 182960 KiB | ||||
46 | Accepted | 321ms | 182684 KiB | ||||
47 | Accepted | 305ms | 182180 KiB | ||||
48 | Accepted | 223ms | 185564 KiB | ||||
49 | Accepted | 202ms | 185380 KiB | ||||
50 | Accepted | 197ms | 182316 KiB | ||||
subtask7 | 0/30 | ||||||
51 | Accepted | 39ms | 79360 KiB | ||||
52 | Accepted | 277ms | 184264 KiB | ||||
53 | Accepted | 39ms | 76840 KiB | ||||
54 | Accepted | 39ms | 77596 KiB | ||||
55 | Accepted | 39ms | 78204 KiB | ||||
56 | Accepted | 39ms | 78080 KiB | ||||
57 | Accepted | 182ms | 176072 KiB | ||||
58 | Accepted | 193ms | 176184 KiB | ||||
59 | Accepted | 188ms | 176356 KiB | ||||
60 | Accepted | 223ms | 195800 KiB | ||||
61 | Accepted | 171ms | 182972 KiB | ||||
62 | Accepted | 173ms | 177880 KiB | ||||
63 | Accepted | 172ms | 178980 KiB | ||||
64 | Accepted | 201ms | 184128 KiB | ||||
65 | Accepted | 222ms | 181796 KiB | ||||
66 | Accepted | 194ms | 179300 KiB | ||||
67 | Accepted | 68ms | 91304 KiB | ||||
68 | Accepted | 59ms | 90872 KiB | ||||
69 | Accepted | 61ms | 90912 KiB | ||||
70 | Accepted | 78ms | 91180 KiB | ||||
71 | Accepted | 70ms | 91264 KiB | ||||
72 | Accepted | 64ms | 91892 KiB | ||||
73 | Accepted | 67ms | 91988 KiB | ||||
74 | Accepted | 63ms | 91204 KiB | ||||
75 | Accepted | 63ms | 91316 KiB | ||||
76 | Accepted | 64ms | 91528 KiB | ||||
77 | Accepted | 65ms | 91516 KiB | ||||
78 | Accepted | 65ms | 91852 KiB | ||||
79 | Accepted | 64ms | 91308 KiB | ||||
80 | Accepted | 300ms | 179244 KiB | ||||
81 | Accepted | 368ms | 183376 KiB | ||||
82 | Accepted | 433ms | 183208 KiB | ||||
83 | Accepted | 386ms | 182960 KiB | ||||
84 | Accepted | 321ms | 182684 KiB | ||||
85 | Accepted | 305ms | 182180 KiB | ||||
86 | Accepted | 223ms | 185564 KiB | ||||
87 | Accepted | 202ms | 185380 KiB | ||||
88 | Accepted | 197ms | 182316 KiB | ||||
89 | Accepted | 389ms | 210480 KiB | ||||
90 | Accepted | 402ms | 216084 KiB | ||||
91 | Accepted | 448ms | 226496 KiB | ||||
92 | Accepted | 476ms | 261220 KiB | ||||
93 | Time limit exceeded | 1.093s | 93252 KiB | ||||
94 | Time limit exceeded | 1.059s | 89940 KiB | ||||
95 | Accepted | 321ms | 186380 KiB | ||||
96 | Accepted | 430ms | 211356 KiB | ||||
97 | Accepted | 280ms | 184836 KiB | ||||
98 | Accepted | 296ms | 179632 KiB | ||||
99 | Accepted | 319ms | 178792 KiB | ||||
100 | Accepted | 361ms | 178868 KiB | ||||
101 | Accepted | 349ms | 184868 KiB |