109562024-04-20 18:42:2042Vállalati ügyeletpypy3Time limit exceeded 70/1001.082s254132 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()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted39ms76352 KiB
2Accepted270ms181768 KiB
subtask25/5
3Accepted39ms76436 KiB
4Accepted46ms76840 KiB
5Accepted43ms77376 KiB
6Accepted46ms78184 KiB
subtask38/8
7Accepted39ms76436 KiB
8Accepted46ms76840 KiB
9Accepted43ms77376 KiB
10Accepted46ms78184 KiB
11Accepted184ms177500 KiB
12Accepted186ms177216 KiB
13Accepted188ms177788 KiB
14Accepted217ms180700 KiB
subtask412/12
15Accepted39ms76436 KiB
16Accepted46ms76840 KiB
17Accepted43ms77376 KiB
18Accepted46ms78184 KiB
19Accepted172ms183284 KiB
20Accepted201ms178568 KiB
21Accepted178ms179664 KiB
22Accepted201ms185004 KiB
23Accepted197ms182296 KiB
24Accepted192ms179916 KiB
subtask517/17
25Accepted39ms76436 KiB
26Accepted46ms76840 KiB
27Accepted43ms77376 KiB
28Accepted46ms78184 KiB
29Accepted71ms91520 KiB
30Accepted67ms91112 KiB
31Accepted68ms91200 KiB
32Accepted72ms91384 KiB
33Accepted70ms91500 KiB
34Accepted64ms92216 KiB
35Accepted65ms91804 KiB
36Accepted71ms92468 KiB
37Accepted65ms92308 KiB
38Accepted64ms92292 KiB
39Accepted79ms92972 KiB
40Accepted68ms92900 KiB
41Accepted64ms92788 KiB
subtask628/28
42Accepted291ms180716 KiB
43Accepted381ms184644 KiB
44Accepted477ms184448 KiB
45Accepted418ms184472 KiB
46Accepted342ms183652 KiB
47Accepted237ms183620 KiB
48Accepted221ms182696 KiB
49Accepted202ms186688 KiB
50Accepted197ms183768 KiB
subtask70/30
51Accepted39ms81120 KiB
52Accepted294ms185876 KiB
53Accepted39ms76436 KiB
54Accepted46ms76840 KiB
55Accepted43ms77376 KiB
56Accepted46ms78184 KiB
57Accepted184ms177500 KiB
58Accepted186ms177216 KiB
59Accepted188ms177788 KiB
60Accepted217ms180700 KiB
61Accepted172ms183284 KiB
62Accepted201ms178568 KiB
63Accepted178ms179664 KiB
64Accepted201ms185004 KiB
65Accepted197ms182296 KiB
66Accepted192ms179916 KiB
67Accepted71ms91520 KiB
68Accepted67ms91112 KiB
69Accepted68ms91200 KiB
70Accepted72ms91384 KiB
71Accepted70ms91500 KiB
72Accepted64ms92216 KiB
73Accepted65ms91804 KiB
74Accepted71ms92468 KiB
75Accepted65ms92308 KiB
76Accepted64ms92292 KiB
77Accepted79ms92972 KiB
78Accepted68ms92900 KiB
79Accepted64ms92788 KiB
80Accepted291ms180716 KiB
81Accepted381ms184644 KiB
82Accepted477ms184448 KiB
83Accepted418ms184472 KiB
84Accepted342ms183652 KiB
85Accepted237ms183620 KiB
86Accepted221ms182696 KiB
87Accepted202ms186688 KiB
88Accepted197ms183768 KiB
89Accepted349ms193720 KiB
90Accepted428ms205260 KiB
91Accepted409ms237400 KiB
92Accepted428ms254132 KiB
93Time limit exceeded1.046s87984 KiB
94Time limit exceeded1.082s90264 KiB
95Accepted248ms188300 KiB
96Accepted472ms218908 KiB
97Accepted277ms186372 KiB
98Accepted254ms181536 KiB
99Accepted282ms180324 KiB
100Accepted331ms180316 KiB
101Accepted263ms186384 KiB