109572024-04-20 18:46:3942Vállalati ügyeletpypy3Time limit exceeded 70/1001.052s248688 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]].update(cur)
                #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
1Accepted39ms76664 KiB
2Accepted289ms181792 KiB
subtask25/5
3Accepted41ms77332 KiB
4Accepted46ms77020 KiB
5Accepted43ms77488 KiB
6Accepted46ms77396 KiB
subtask38/8
7Accepted41ms77332 KiB
8Accepted46ms77020 KiB
9Accepted43ms77488 KiB
10Accepted46ms77396 KiB
11Accepted182ms176828 KiB
12Accepted184ms176892 KiB
13Accepted212ms176816 KiB
14Accepted250ms179872 KiB
subtask412/12
15Accepted41ms77332 KiB
16Accepted46ms77020 KiB
17Accepted43ms77488 KiB
18Accepted46ms77396 KiB
19Accepted199ms182708 KiB
20Accepted178ms177340 KiB
21Accepted209ms178956 KiB
22Accepted234ms184748 KiB
23Accepted197ms182340 KiB
24Accepted219ms179920 KiB
subtask517/17
25Accepted41ms77332 KiB
26Accepted46ms77020 KiB
27Accepted43ms77488 KiB
28Accepted46ms77396 KiB
29Accepted65ms92272 KiB
30Accepted67ms91456 KiB
31Accepted68ms91676 KiB
32Accepted72ms91920 KiB
33Accepted75ms91468 KiB
34Accepted74ms91616 KiB
35Accepted75ms91748 KiB
36Accepted67ms91968 KiB
37Accepted71ms92304 KiB
38Accepted74ms92516 KiB
39Accepted75ms92704 KiB
40Accepted72ms92768 KiB
41Accepted78ms92292 KiB
subtask628/28
42Accepted316ms180716 KiB
43Accepted347ms184124 KiB
44Accepted381ms184152 KiB
45Accepted381ms184120 KiB
46Accepted273ms183576 KiB
47Accepted223ms183748 KiB
48Accepted217ms182808 KiB
49Accepted201ms186468 KiB
50Accepted197ms183688 KiB
subtask70/30
51Accepted48ms80512 KiB
52Accepted273ms185644 KiB
53Accepted41ms77332 KiB
54Accepted46ms77020 KiB
55Accepted43ms77488 KiB
56Accepted46ms77396 KiB
57Accepted182ms176828 KiB
58Accepted184ms176892 KiB
59Accepted212ms176816 KiB
60Accepted250ms179872 KiB
61Accepted199ms182708 KiB
62Accepted178ms177340 KiB
63Accepted209ms178956 KiB
64Accepted234ms184748 KiB
65Accepted197ms182340 KiB
66Accepted219ms179920 KiB
67Accepted65ms92272 KiB
68Accepted67ms91456 KiB
69Accepted68ms91676 KiB
70Accepted72ms91920 KiB
71Accepted75ms91468 KiB
72Accepted74ms91616 KiB
73Accepted75ms91748 KiB
74Accepted67ms91968 KiB
75Accepted71ms92304 KiB
76Accepted74ms92516 KiB
77Accepted75ms92704 KiB
78Accepted72ms92768 KiB
79Accepted78ms92292 KiB
80Accepted316ms180716 KiB
81Accepted347ms184124 KiB
82Accepted381ms184152 KiB
83Accepted381ms184120 KiB
84Accepted273ms183576 KiB
85Accepted223ms183748 KiB
86Accepted217ms182808 KiB
87Accepted201ms186468 KiB
88Accepted197ms183688 KiB
89Accepted430ms199600 KiB
90Accepted351ms201676 KiB
91Accepted407ms239448 KiB
92Accepted430ms248688 KiB
93Time limit exceeded1.052s94568 KiB
94Time limit exceeded1.032s92432 KiB
95Accepted282ms188056 KiB
96Accepted474ms221156 KiB
97Accepted296ms186220 KiB
98Accepted270ms181332 KiB
99Accepted293ms180040 KiB
100Accepted275ms179844 KiB
101Accepted239ms185940 KiB