109522024-04-20 18:34:5342Vállalati ügyeletpypy3Time limit exceeded 70/1001.088s254460 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)+100:
                #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
1Accepted45ms76848 KiB
2Accepted280ms181892 KiB
subtask25/5
3Accepted39ms77580 KiB
4Accepted39ms77524 KiB
5Accepted39ms77272 KiB
6Accepted39ms77616 KiB
subtask38/8
7Accepted39ms77580 KiB
8Accepted39ms77524 KiB
9Accepted39ms77272 KiB
10Accepted39ms77616 KiB
11Accepted212ms177248 KiB
12Accepted189ms177120 KiB
13Accepted187ms177244 KiB
14Accepted219ms196404 KiB
subtask412/12
15Accepted39ms77580 KiB
16Accepted39ms77524 KiB
17Accepted39ms77272 KiB
18Accepted39ms77616 KiB
19Accepted200ms183016 KiB
20Accepted177ms177808 KiB
21Accepted172ms179020 KiB
22Accepted201ms184644 KiB
23Accepted222ms182260 KiB
24Accepted193ms179644 KiB
subtask517/17
25Accepted39ms77580 KiB
26Accepted39ms77524 KiB
27Accepted39ms77272 KiB
28Accepted39ms77616 KiB
29Accepted64ms91716 KiB
30Accepted68ms91232 KiB
31Accepted64ms91232 KiB
32Accepted78ms91404 KiB
33Accepted70ms91292 KiB
34Accepted64ms92280 KiB
35Accepted74ms92448 KiB
36Accepted67ms91608 KiB
37Accepted70ms91724 KiB
38Accepted68ms92312 KiB
39Accepted65ms92328 KiB
40Accepted65ms92856 KiB
41Accepted64ms92200 KiB
subtask628/28
42Accepted300ms180632 KiB
43Accepted384ms183948 KiB
44Accepted400ms184020 KiB
45Accepted337ms183900 KiB
46Accepted270ms183176 KiB
47Accepted224ms183316 KiB
48Accepted221ms198056 KiB
49Accepted236ms186444 KiB
50Accepted228ms183352 KiB
subtask70/30
51Accepted48ms80420 KiB
52Accepted280ms185244 KiB
53Accepted39ms77580 KiB
54Accepted39ms77524 KiB
55Accepted39ms77272 KiB
56Accepted39ms77616 KiB
57Accepted212ms177248 KiB
58Accepted189ms177120 KiB
59Accepted187ms177244 KiB
60Accepted219ms196404 KiB
61Accepted200ms183016 KiB
62Accepted177ms177808 KiB
63Accepted172ms179020 KiB
64Accepted201ms184644 KiB
65Accepted222ms182260 KiB
66Accepted193ms179644 KiB
67Accepted64ms91716 KiB
68Accepted68ms91232 KiB
69Accepted64ms91232 KiB
70Accepted78ms91404 KiB
71Accepted70ms91292 KiB
72Accepted64ms92280 KiB
73Accepted74ms92448 KiB
74Accepted67ms91608 KiB
75Accepted70ms91724 KiB
76Accepted68ms92312 KiB
77Accepted65ms92328 KiB
78Accepted65ms92856 KiB
79Accepted64ms92200 KiB
80Accepted300ms180632 KiB
81Accepted384ms183948 KiB
82Accepted400ms184020 KiB
83Accepted337ms183900 KiB
84Accepted270ms183176 KiB
85Accepted224ms183316 KiB
86Accepted221ms198056 KiB
87Accepted236ms186444 KiB
88Accepted228ms183352 KiB
89Accepted515ms210280 KiB
90Accepted509ms221492 KiB
91Accepted546ms229804 KiB
92Accepted582ms254460 KiB
93Time limit exceeded1.088s94352 KiB
94Time limit exceeded1.049s91064 KiB
95Accepted248ms188040 KiB
96Accepted425ms217108 KiB
97Accepted280ms186252 KiB
98Accepted284ms181168 KiB
99Accepted282ms180304 KiB
100Accepted280ms180164 KiB
101Accepted277ms185964 KiB