109492024-04-20 18:22:0642Vállalati ügyeletpypy3Time limit exceeded 70/1001.07s241200 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):
                #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
1Accepted41ms76348 KiB
2Accepted289ms181540 KiB
subtask25/5
3Accepted43ms77128 KiB
4Accepted46ms77268 KiB
5Accepted46ms77528 KiB
6Accepted43ms77744 KiB
subtask38/8
7Accepted43ms77128 KiB
8Accepted46ms77268 KiB
9Accepted46ms77528 KiB
10Accepted43ms77744 KiB
11Accepted206ms177516 KiB
12Accepted187ms177332 KiB
13Accepted187ms177800 KiB
14Accepted221ms180964 KiB
subtask412/12
15Accepted43ms77128 KiB
16Accepted46ms77268 KiB
17Accepted46ms77528 KiB
18Accepted43ms77744 KiB
19Accepted200ms183600 KiB
20Accepted178ms178484 KiB
21Accepted173ms179768 KiB
22Accepted201ms185288 KiB
23Accepted196ms182592 KiB
24Accepted193ms180516 KiB
subtask517/17
25Accepted43ms77128 KiB
26Accepted46ms77268 KiB
27Accepted46ms77528 KiB
28Accepted43ms77744 KiB
29Accepted64ms92360 KiB
30Accepted71ms91992 KiB
31Accepted64ms91796 KiB
32Accepted71ms92112 KiB
33Accepted70ms92048 KiB
34Accepted64ms92796 KiB
35Accepted64ms92072 KiB
36Accepted63ms91948 KiB
37Accepted70ms92236 KiB
38Accepted68ms92080 KiB
39Accepted65ms92356 KiB
40Accepted65ms92168 KiB
41Accepted64ms92100 KiB
subtask628/28
42Accepted286ms181116 KiB
43Accepted349ms183860 KiB
44Accepted384ms183568 KiB
45Accepted337ms184100 KiB
46Accepted303ms183348 KiB
47Accepted248ms183224 KiB
48Accepted224ms182192 KiB
49Accepted236ms186124 KiB
50Accepted222ms183196 KiB
subtask70/30
51Accepted41ms80116 KiB
52Accepted261ms184996 KiB
53Accepted43ms77128 KiB
54Accepted46ms77268 KiB
55Accepted46ms77528 KiB
56Accepted43ms77744 KiB
57Accepted206ms177516 KiB
58Accepted187ms177332 KiB
59Accepted187ms177800 KiB
60Accepted221ms180964 KiB
61Accepted200ms183600 KiB
62Accepted178ms178484 KiB
63Accepted173ms179768 KiB
64Accepted201ms185288 KiB
65Accepted196ms182592 KiB
66Accepted193ms180516 KiB
67Accepted64ms92360 KiB
68Accepted71ms91992 KiB
69Accepted64ms91796 KiB
70Accepted71ms92112 KiB
71Accepted70ms92048 KiB
72Accepted64ms92796 KiB
73Accepted64ms92072 KiB
74Accepted63ms91948 KiB
75Accepted70ms92236 KiB
76Accepted68ms92080 KiB
77Accepted65ms92356 KiB
78Accepted65ms92168 KiB
79Accepted64ms92100 KiB
80Accepted286ms181116 KiB
81Accepted349ms183860 KiB
82Accepted384ms183568 KiB
83Accepted337ms184100 KiB
84Accepted303ms183348 KiB
85Accepted248ms183224 KiB
86Accepted224ms182192 KiB
87Accepted236ms186124 KiB
88Accepted222ms183196 KiB
89Accepted360ms200000 KiB
90Accepted397ms199280 KiB
91Accepted414ms231340 KiB
92Accepted433ms241200 KiB
93Time limit exceeded1.07s93968 KiB
94Time limit exceeded1.07s90336 KiB
95Accepted275ms187528 KiB
96Accepted393ms218468 KiB
97Accepted272ms185748 KiB
98Accepted248ms180908 KiB
99Accepted257ms179756 KiB
100Accepted273ms179628 KiB
101Accepted280ms185312 KiB