109512024-04-20 18:32:1042Vállalati ügyeletpypy3Time limit exceeded 70/1001.05s250596 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)+10:
                #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
1Accepted50ms76544 KiB
2Accepted280ms181828 KiB
subtask25/5
3Accepted46ms77348 KiB
4Accepted43ms77544 KiB
5Accepted39ms77680 KiB
6Accepted46ms78024 KiB
subtask38/8
7Accepted46ms77348 KiB
8Accepted43ms77544 KiB
9Accepted39ms77680 KiB
10Accepted46ms78024 KiB
11Accepted207ms178156 KiB
12Accepted210ms177748 KiB
13Accepted189ms177652 KiB
14Accepted259ms180936 KiB
subtask412/12
15Accepted46ms77348 KiB
16Accepted43ms77544 KiB
17Accepted39ms77680 KiB
18Accepted46ms78024 KiB
19Accepted173ms183572 KiB
20Accepted202ms178596 KiB
21Accepted179ms180212 KiB
22Accepted201ms185660 KiB
23Accepted221ms182844 KiB
24Accepted193ms180660 KiB
subtask517/17
25Accepted46ms77348 KiB
26Accepted43ms77544 KiB
27Accepted39ms77680 KiB
28Accepted46ms78024 KiB
29Accepted64ms92408 KiB
30Accepted59ms91992 KiB
31Accepted61ms92168 KiB
32Accepted64ms92400 KiB
33Accepted67ms91968 KiB
34Accepted64ms92812 KiB
35Accepted65ms92912 KiB
36Accepted63ms92108 KiB
37Accepted63ms92356 KiB
38Accepted65ms92652 KiB
39Accepted67ms92660 KiB
40Accepted64ms93120 KiB
41Accepted64ms92360 KiB
subtask628/28
42Accepted331ms181536 KiB
43Accepted358ms184468 KiB
44Accepted386ms184300 KiB
45Accepted381ms184272 KiB
46Accepted268ms183680 KiB
47Accepted221ms183652 KiB
48Accepted218ms182568 KiB
49Accepted202ms186488 KiB
50Accepted194ms183560 KiB
subtask70/30
51Accepted39ms80420 KiB
52Accepted275ms185032 KiB
53Accepted46ms77348 KiB
54Accepted43ms77544 KiB
55Accepted39ms77680 KiB
56Accepted46ms78024 KiB
57Accepted207ms178156 KiB
58Accepted210ms177748 KiB
59Accepted189ms177652 KiB
60Accepted259ms180936 KiB
61Accepted173ms183572 KiB
62Accepted202ms178596 KiB
63Accepted179ms180212 KiB
64Accepted201ms185660 KiB
65Accepted221ms182844 KiB
66Accepted193ms180660 KiB
67Accepted64ms92408 KiB
68Accepted59ms91992 KiB
69Accepted61ms92168 KiB
70Accepted64ms92400 KiB
71Accepted67ms91968 KiB
72Accepted64ms92812 KiB
73Accepted65ms92912 KiB
74Accepted63ms92108 KiB
75Accepted63ms92356 KiB
76Accepted65ms92652 KiB
77Accepted67ms92660 KiB
78Accepted64ms93120 KiB
79Accepted64ms92360 KiB
80Accepted331ms181536 KiB
81Accepted358ms184468 KiB
82Accepted386ms184300 KiB
83Accepted381ms184272 KiB
84Accepted268ms183680 KiB
85Accepted221ms183652 KiB
86Accepted218ms182568 KiB
87Accepted202ms186488 KiB
88Accepted194ms183560 KiB
89Accepted389ms205080 KiB
90Accepted393ms216064 KiB
91Accepted541ms223620 KiB
92Accepted583ms250596 KiB
93Time limit exceeded1.049s94396 KiB
94Time limit exceeded1.05s91332 KiB
95Accepted236ms187948 KiB
96Accepted476ms219248 KiB
97Accepted287ms186012 KiB
98Accepted287ms181112 KiB
99Accepted272ms180116 KiB
100Accepted282ms179596 KiB
101Accepted252ms185640 KiB