10947 | 2024-04-20 18:15:46 | 42 | Vállalati ügyelet | python3 | Time limit exceeded 34/100 | 1.077s | 105172 KiB |
from sys import stdin, stdout
input=stdin.readline
def main():
N = int(input())
P = [0]+list(map(int, input().split()))
A = [0]+[int(x) for x in 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):
A[P[i]]=A[P[i]].union(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 | 18ms | 11408 KiB | ||||
2 | Accepted | 713ms | 73564 KiB | ||||
subtask2 | 5/5 | ||||||
3 | Accepted | 18ms | 11812 KiB | ||||
4 | Accepted | 17ms | 11916 KiB | ||||
5 | Accepted | 18ms | 12232 KiB | ||||
6 | Accepted | 17ms | 12204 KiB | ||||
subtask3 | 0/8 | ||||||
7 | Accepted | 18ms | 11812 KiB | ||||
8 | Accepted | 17ms | 11916 KiB | ||||
9 | Accepted | 18ms | 12232 KiB | ||||
10 | Accepted | 17ms | 12204 KiB | ||||
11 | Time limit exceeded | 1.059s | 30328 KiB | ||||
12 | Time limit exceeded | 1.06s | 30852 KiB | ||||
13 | Time limit exceeded | 1.065s | 29288 KiB | ||||
14 | Time limit exceeded | 1.065s | 29884 KiB | ||||
subtask4 | 12/12 | ||||||
15 | Accepted | 18ms | 11812 KiB | ||||
16 | Accepted | 17ms | 11916 KiB | ||||
17 | Accepted | 18ms | 12232 KiB | ||||
18 | Accepted | 17ms | 12204 KiB | ||||
19 | Accepted | 432ms | 76948 KiB | ||||
20 | Accepted | 423ms | 77260 KiB | ||||
21 | Accepted | 460ms | 77744 KiB | ||||
22 | Accepted | 526ms | 80348 KiB | ||||
23 | Accepted | 458ms | 78544 KiB | ||||
24 | Accepted | 439ms | 78244 KiB | ||||
subtask5 | 17/17 | ||||||
25 | Accepted | 18ms | 11812 KiB | ||||
26 | Accepted | 17ms | 11916 KiB | ||||
27 | Accepted | 18ms | 12232 KiB | ||||
28 | Accepted | 17ms | 12204 KiB | ||||
29 | Accepted | 46ms | 14676 KiB | ||||
30 | Accepted | 21ms | 15444 KiB | ||||
31 | Accepted | 21ms | 14972 KiB | ||||
32 | Accepted | 23ms | 15268 KiB | ||||
33 | Accepted | 24ms | 15292 KiB | ||||
34 | Accepted | 23ms | 15460 KiB | ||||
35 | Accepted | 24ms | 15768 KiB | ||||
36 | Accepted | 23ms | 15264 KiB | ||||
37 | Accepted | 23ms | 15800 KiB | ||||
38 | Accepted | 23ms | 15460 KiB | ||||
39 | Accepted | 23ms | 15388 KiB | ||||
40 | Accepted | 23ms | 15524 KiB | ||||
41 | Accepted | 21ms | 15288 KiB | ||||
subtask6 | 0/28 | ||||||
42 | Accepted | 816ms | 79300 KiB | ||||
43 | Time limit exceeded | 1.062s | 39644 KiB | ||||
44 | Time limit exceeded | 1.077s | 39608 KiB | ||||
45 | Time limit exceeded | 1.077s | 39548 KiB | ||||
46 | Time limit exceeded | 1.049s | 39704 KiB | ||||
47 | Accepted | 568ms | 79524 KiB | ||||
48 | Time limit exceeded | 1.057s | 31892 KiB | ||||
49 | Accepted | 519ms | 81624 KiB | ||||
50 | Accepted | 456ms | 79572 KiB | ||||
subtask7 | 0/30 | ||||||
51 | Accepted | 17ms | 15312 KiB | ||||
52 | Accepted | 726ms | 76876 KiB | ||||
53 | Accepted | 18ms | 11812 KiB | ||||
54 | Accepted | 17ms | 11916 KiB | ||||
55 | Accepted | 18ms | 12232 KiB | ||||
56 | Accepted | 17ms | 12204 KiB | ||||
57 | Time limit exceeded | 1.059s | 30328 KiB | ||||
58 | Time limit exceeded | 1.06s | 30852 KiB | ||||
59 | Time limit exceeded | 1.065s | 29288 KiB | ||||
60 | Time limit exceeded | 1.065s | 29884 KiB | ||||
61 | Accepted | 432ms | 76948 KiB | ||||
62 | Accepted | 423ms | 77260 KiB | ||||
63 | Accepted | 460ms | 77744 KiB | ||||
64 | Accepted | 526ms | 80348 KiB | ||||
65 | Accepted | 458ms | 78544 KiB | ||||
66 | Accepted | 439ms | 78244 KiB | ||||
67 | Accepted | 46ms | 14676 KiB | ||||
68 | Accepted | 21ms | 15444 KiB | ||||
69 | Accepted | 21ms | 14972 KiB | ||||
70 | Accepted | 23ms | 15268 KiB | ||||
71 | Accepted | 24ms | 15292 KiB | ||||
72 | Accepted | 23ms | 15460 KiB | ||||
73 | Accepted | 24ms | 15768 KiB | ||||
74 | Accepted | 23ms | 15264 KiB | ||||
75 | Accepted | 23ms | 15800 KiB | ||||
76 | Accepted | 23ms | 15460 KiB | ||||
77 | Accepted | 23ms | 15388 KiB | ||||
78 | Accepted | 23ms | 15524 KiB | ||||
79 | Accepted | 21ms | 15288 KiB | ||||
80 | Accepted | 816ms | 79300 KiB | ||||
81 | Time limit exceeded | 1.062s | 39644 KiB | ||||
82 | Time limit exceeded | 1.077s | 39608 KiB | ||||
83 | Time limit exceeded | 1.077s | 39548 KiB | ||||
84 | Time limit exceeded | 1.049s | 39704 KiB | ||||
85 | Accepted | 568ms | 79524 KiB | ||||
86 | Time limit exceeded | 1.057s | 31892 KiB | ||||
87 | Accepted | 519ms | 81624 KiB | ||||
88 | Accepted | 456ms | 79572 KiB | ||||
89 | Accepted | 663ms | 83832 KiB | ||||
90 | Accepted | 726ms | 92256 KiB | ||||
91 | Accepted | 855ms | 105172 KiB | ||||
92 | Accepted | 890ms | 103896 KiB | ||||
93 | Time limit exceeded | 1.054s | 30584 KiB | ||||
94 | Time limit exceeded | 1.07s | 34688 KiB | ||||
95 | Accepted | 632ms | 91548 KiB | ||||
96 | Accepted | 978ms | 78696 KiB | ||||
97 | Accepted | 739ms | 75780 KiB | ||||
98 | Accepted | 563ms | 66812 KiB | ||||
99 | Accepted | 698ms | 78964 KiB | ||||
100 | Accepted | 880ms | 77020 KiB | ||||
101 | Accepted | 591ms | 70996 KiB |