109542024-04-20 18:38:2842Vállalati ügyeletpypy3Time limit exceeded 70/1001.075s236884 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
1Accepted48ms76312 KiB
2Accepted264ms181828 KiB
subtask25/5
3Accepted46ms77360 KiB
4Accepted46ms77668 KiB
5Accepted46ms77756 KiB
6Accepted46ms78200 KiB
subtask38/8
7Accepted46ms77360 KiB
8Accepted46ms77668 KiB
9Accepted46ms77756 KiB
10Accepted46ms78200 KiB
11Accepted208ms177268 KiB
12Accepted211ms177280 KiB
13Accepted216ms177252 KiB
14Accepted222ms180588 KiB
subtask412/12
15Accepted46ms77360 KiB
16Accepted46ms77668 KiB
17Accepted46ms77756 KiB
18Accepted46ms78200 KiB
19Accepted172ms183372 KiB
20Accepted202ms178420 KiB
21Accepted202ms179396 KiB
22Accepted206ms185216 KiB
23Accepted194ms182532 KiB
24Accepted190ms180320 KiB
subtask517/17
25Accepted46ms77360 KiB
26Accepted46ms77668 KiB
27Accepted46ms77756 KiB
28Accepted46ms78200 KiB
29Accepted64ms91940 KiB
30Accepted68ms91836 KiB
31Accepted64ms91852 KiB
32Accepted71ms91780 KiB
33Accepted75ms91848 KiB
34Accepted78ms92576 KiB
35Accepted74ms92552 KiB
36Accepted67ms92304 KiB
37Accepted63ms92516 KiB
38Accepted64ms92136 KiB
39Accepted74ms92700 KiB
40Accepted74ms92748 KiB
41Accepted68ms92740 KiB
subtask628/28
42Accepted317ms181592 KiB
43Accepted372ms184316 KiB
44Accepted409ms184108 KiB
45Accepted377ms184040 KiB
46Accepted294ms183324 KiB
47Accepted226ms183344 KiB
48Accepted221ms182172 KiB
49Accepted203ms186244 KiB
50Accepted222ms183116 KiB
subtask70/30
51Accepted46ms80656 KiB
52Accepted266ms185116 KiB
53Accepted46ms77360 KiB
54Accepted46ms77668 KiB
55Accepted46ms77756 KiB
56Accepted46ms78200 KiB
57Accepted208ms177268 KiB
58Accepted211ms177280 KiB
59Accepted216ms177252 KiB
60Accepted222ms180588 KiB
61Accepted172ms183372 KiB
62Accepted202ms178420 KiB
63Accepted202ms179396 KiB
64Accepted206ms185216 KiB
65Accepted194ms182532 KiB
66Accepted190ms180320 KiB
67Accepted64ms91940 KiB
68Accepted68ms91836 KiB
69Accepted64ms91852 KiB
70Accepted71ms91780 KiB
71Accepted75ms91848 KiB
72Accepted78ms92576 KiB
73Accepted74ms92552 KiB
74Accepted67ms92304 KiB
75Accepted63ms92516 KiB
76Accepted64ms92136 KiB
77Accepted74ms92700 KiB
78Accepted74ms92748 KiB
79Accepted68ms92740 KiB
80Accepted317ms181592 KiB
81Accepted372ms184316 KiB
82Accepted409ms184108 KiB
83Accepted377ms184040 KiB
84Accepted294ms183324 KiB
85Accepted226ms183344 KiB
86Accepted221ms182172 KiB
87Accepted203ms186244 KiB
88Accepted222ms183116 KiB
89Accepted439ms193276 KiB
90Accepted351ms198176 KiB
91Accepted398ms224208 KiB
92Accepted426ms236884 KiB
93Time limit exceeded1.075s94144 KiB
94Time limit exceeded1.07s89724 KiB
95Accepted238ms188000 KiB
96Accepted472ms218900 KiB
97Accepted273ms186268 KiB
98Accepted244ms181348 KiB
99Accepted284ms180060 KiB
100Accepted303ms179692 KiB
101Accepted243ms185896 KiB