109532024-04-20 18:37:1742Vállalati ügyeletpypy3Time limit exceeded 70/1001.093s261220 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()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted41ms76784 KiB
2Accepted275ms181644 KiB
subtask25/5
3Accepted39ms76840 KiB
4Accepted39ms77596 KiB
5Accepted39ms78204 KiB
6Accepted39ms78080 KiB
subtask38/8
7Accepted39ms76840 KiB
8Accepted39ms77596 KiB
9Accepted39ms78204 KiB
10Accepted39ms78080 KiB
11Accepted182ms176072 KiB
12Accepted193ms176184 KiB
13Accepted188ms176356 KiB
14Accepted223ms195800 KiB
subtask412/12
15Accepted39ms76840 KiB
16Accepted39ms77596 KiB
17Accepted39ms78204 KiB
18Accepted39ms78080 KiB
19Accepted171ms182972 KiB
20Accepted173ms177880 KiB
21Accepted172ms178980 KiB
22Accepted201ms184128 KiB
23Accepted222ms181796 KiB
24Accepted194ms179300 KiB
subtask517/17
25Accepted39ms76840 KiB
26Accepted39ms77596 KiB
27Accepted39ms78204 KiB
28Accepted39ms78080 KiB
29Accepted68ms91304 KiB
30Accepted59ms90872 KiB
31Accepted61ms90912 KiB
32Accepted78ms91180 KiB
33Accepted70ms91264 KiB
34Accepted64ms91892 KiB
35Accepted67ms91988 KiB
36Accepted63ms91204 KiB
37Accepted63ms91316 KiB
38Accepted64ms91528 KiB
39Accepted65ms91516 KiB
40Accepted65ms91852 KiB
41Accepted64ms91308 KiB
subtask628/28
42Accepted300ms179244 KiB
43Accepted368ms183376 KiB
44Accepted433ms183208 KiB
45Accepted386ms182960 KiB
46Accepted321ms182684 KiB
47Accepted305ms182180 KiB
48Accepted223ms185564 KiB
49Accepted202ms185380 KiB
50Accepted197ms182316 KiB
subtask70/30
51Accepted39ms79360 KiB
52Accepted277ms184264 KiB
53Accepted39ms76840 KiB
54Accepted39ms77596 KiB
55Accepted39ms78204 KiB
56Accepted39ms78080 KiB
57Accepted182ms176072 KiB
58Accepted193ms176184 KiB
59Accepted188ms176356 KiB
60Accepted223ms195800 KiB
61Accepted171ms182972 KiB
62Accepted173ms177880 KiB
63Accepted172ms178980 KiB
64Accepted201ms184128 KiB
65Accepted222ms181796 KiB
66Accepted194ms179300 KiB
67Accepted68ms91304 KiB
68Accepted59ms90872 KiB
69Accepted61ms90912 KiB
70Accepted78ms91180 KiB
71Accepted70ms91264 KiB
72Accepted64ms91892 KiB
73Accepted67ms91988 KiB
74Accepted63ms91204 KiB
75Accepted63ms91316 KiB
76Accepted64ms91528 KiB
77Accepted65ms91516 KiB
78Accepted65ms91852 KiB
79Accepted64ms91308 KiB
80Accepted300ms179244 KiB
81Accepted368ms183376 KiB
82Accepted433ms183208 KiB
83Accepted386ms182960 KiB
84Accepted321ms182684 KiB
85Accepted305ms182180 KiB
86Accepted223ms185564 KiB
87Accepted202ms185380 KiB
88Accepted197ms182316 KiB
89Accepted389ms210480 KiB
90Accepted402ms216084 KiB
91Accepted448ms226496 KiB
92Accepted476ms261220 KiB
93Time limit exceeded1.093s93252 KiB
94Time limit exceeded1.059s89940 KiB
95Accepted321ms186380 KiB
96Accepted430ms211356 KiB
97Accepted280ms184836 KiB
98Accepted296ms179632 KiB
99Accepted319ms178792 KiB
100Accepted361ms178868 KiB
101Accepted349ms184868 KiB