109482024-04-20 18:16:3742Vállalati ügyeletpypy3Time limit exceeded 34/1001.093s247648 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()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted46ms76732 KiB
2Accepted308ms172080 KiB
subtask25/5
3Accepted46ms77284 KiB
4Accepted43ms77356 KiB
5Accepted48ms78180 KiB
6Accepted43ms77392 KiB
subtask30/8
7Accepted46ms77284 KiB
8Accepted43ms77356 KiB
9Accepted48ms78180 KiB
10Accepted43ms77392 KiB
11Time limit exceeded1.082s78104 KiB
12Time limit exceeded1.093s79524 KiB
13Time limit exceeded1.044s77472 KiB
14Time limit exceeded1.06s78180 KiB
subtask412/12
15Accepted46ms77284 KiB
16Accepted43ms77356 KiB
17Accepted48ms78180 KiB
18Accepted43ms77392 KiB
19Accepted194ms164148 KiB
20Accepted202ms163548 KiB
21Accepted195ms165816 KiB
22Accepted243ms195240 KiB
23Accepted215ms166976 KiB
24Accepted189ms172772 KiB
subtask517/17
25Accepted46ms77284 KiB
26Accepted43ms77356 KiB
27Accepted48ms78180 KiB
28Accepted43ms77392 KiB
29Accepted86ms92836 KiB
30Accepted72ms90968 KiB
31Accepted71ms91008 KiB
32Accepted75ms92000 KiB
33Accepted76ms91952 KiB
34Accepted70ms92016 KiB
35Accepted75ms92416 KiB
36Accepted74ms91856 KiB
37Accepted78ms92264 KiB
38Accepted70ms91780 KiB
39Accepted75ms92388 KiB
40Accepted75ms92108 KiB
41Accepted74ms92132 KiB
subtask60/28
42Accepted365ms180728 KiB
43Accepted532ms179596 KiB
44Accepted680ms180260 KiB
45Accepted605ms180288 KiB
46Accepted423ms178740 KiB
47Accepted254ms168216 KiB
48Time limit exceeded1.077s80236 KiB
49Accepted202ms196060 KiB
50Accepted193ms168440 KiB
subtask70/30
51Accepted41ms80636 KiB
52Accepted305ms175880 KiB
53Accepted46ms77284 KiB
54Accepted43ms77356 KiB
55Accepted48ms78180 KiB
56Accepted43ms77392 KiB
57Time limit exceeded1.082s78104 KiB
58Time limit exceeded1.093s79524 KiB
59Time limit exceeded1.044s77472 KiB
60Time limit exceeded1.06s78180 KiB
61Accepted194ms164148 KiB
62Accepted202ms163548 KiB
63Accepted195ms165816 KiB
64Accepted243ms195240 KiB
65Accepted215ms166976 KiB
66Accepted189ms172772 KiB
67Accepted86ms92836 KiB
68Accepted72ms90968 KiB
69Accepted71ms91008 KiB
70Accepted75ms92000 KiB
71Accepted76ms91952 KiB
72Accepted70ms92016 KiB
73Accepted75ms92416 KiB
74Accepted74ms91856 KiB
75Accepted78ms92264 KiB
76Accepted70ms91780 KiB
77Accepted75ms92388 KiB
78Accepted75ms92108 KiB
79Accepted74ms92132 KiB
80Accepted365ms180728 KiB
81Accepted532ms179596 KiB
82Accepted680ms180260 KiB
83Accepted605ms180288 KiB
84Accepted423ms178740 KiB
85Accepted254ms168216 KiB
86Time limit exceeded1.077s80236 KiB
87Accepted202ms196060 KiB
88Accepted193ms168440 KiB
89Accepted393ms212072 KiB
90Accepted495ms221820 KiB
91Accepted458ms229428 KiB
92Accepted595ms247648 KiB
93Time limit exceeded1.042s94648 KiB
94Time limit exceeded1.057s89288 KiB
95Accepted280ms210736 KiB
96Accepted717ms218296 KiB
97Accepted358ms178884 KiB
98Accepted289ms162528 KiB
99Accepted317ms168136 KiB
100Accepted389ms174204 KiB
101Accepted277ms166172 KiB