109432024-04-20 17:56:5642Vállalati ügyeletpypy3Runtime error 22/1001.093s301404 KiB
from sys import stdin, stdout
input=stdin.readline

def main():
    N = int(input())
    P = [0]+list(map(int, input().split()))
    A = [set()]+[{int(x)} for x in input().split()]
    res=[1]*(N+1)
    for i in range(N,0,-1):
        while res[i] in A[i]:
            A[i].remove(res[i])
            res[i]+=1
        res[P[i]]=max(res[i],res[P[i]])
        if len(A[P[i]]) >= len(A[i]):
            A[P[i]]=A[P[i]].union(A.pop())
        else:
            A[P[i]]=A.pop().union(A[P[i]])
        #print(A)
    #print(A)
    print(*res[1:])
    #stdout.write(''.join(A))
    #stdout.write('\n')
        
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted43ms76112 KiB
2Accepted476ms249504 KiB
subtask25/5
3Accepted39ms76852 KiB
4Accepted39ms77096 KiB
5Accepted39ms77584 KiB
6Accepted39ms77404 KiB
subtask30/8
7Accepted39ms76852 KiB
8Accepted39ms77096 KiB
9Accepted39ms77584 KiB
10Accepted39ms77404 KiB
11Runtime error703ms301348 KiB
12Runtime error867ms301404 KiB
13Time limit exceeded1.088s130428 KiB
14Runtime error676ms301124 KiB
subtask40/12
15Accepted39ms76852 KiB
16Accepted39ms77096 KiB
17Accepted39ms77584 KiB
18Accepted39ms77404 KiB
19Runtime error699ms300844 KiB
20Runtime error897ms300932 KiB
21Time limit exceeded1.08s128272 KiB
22Runtime error587ms300580 KiB
23Accepted356ms231976 KiB
24Runtime error755ms300416 KiB
subtask517/17
25Accepted39ms76852 KiB
26Accepted39ms77096 KiB
27Accepted39ms77584 KiB
28Accepted39ms77404 KiB
29Accepted82ms93884 KiB
30Accepted76ms92684 KiB
31Accepted68ms92324 KiB
32Accepted68ms93080 KiB
33Accepted82ms92812 KiB
34Accepted71ms92476 KiB
35Accepted68ms92788 KiB
36Accepted68ms92480 KiB
37Accepted74ms92924 KiB
38Accepted70ms93640 KiB
39Accepted81ms93480 KiB
40Accepted72ms94028 KiB
41Accepted78ms93388 KiB
subtask60/28
42Accepted492ms280128 KiB
43Accepted828ms273176 KiB
44Time limit exceeded1.093s119720 KiB
45Time limit exceeded1.055s120132 KiB
46Time limit exceeded1.055s119996 KiB
47Time limit exceeded1.021s274492 KiB
48Runtime error610ms298680 KiB
49Runtime error578ms298432 KiB
50Accepted360ms233932 KiB
subtask70/30
51Accepted39ms80552 KiB
52Accepted541ms253380 KiB
53Accepted39ms76852 KiB
54Accepted39ms77096 KiB
55Accepted39ms77584 KiB
56Accepted39ms77404 KiB
57Runtime error703ms301348 KiB
58Runtime error867ms301404 KiB
59Time limit exceeded1.088s130428 KiB
60Runtime error676ms301124 KiB
61Runtime error699ms300844 KiB
62Runtime error897ms300932 KiB
63Time limit exceeded1.08s128272 KiB
64Runtime error587ms300580 KiB
65Accepted356ms231976 KiB
66Runtime error755ms300416 KiB
67Accepted82ms93884 KiB
68Accepted76ms92684 KiB
69Accepted68ms92324 KiB
70Accepted68ms93080 KiB
71Accepted82ms92812 KiB
72Accepted71ms92476 KiB
73Accepted68ms92788 KiB
74Accepted68ms92480 KiB
75Accepted74ms92924 KiB
76Accepted70ms93640 KiB
77Accepted81ms93480 KiB
78Accepted72ms94028 KiB
79Accepted78ms93388 KiB
80Accepted492ms280128 KiB
81Accepted828ms273176 KiB
82Time limit exceeded1.093s119720 KiB
83Time limit exceeded1.055s120132 KiB
84Time limit exceeded1.055s119996 KiB
85Time limit exceeded1.021s274492 KiB
86Runtime error610ms298680 KiB
87Runtime error578ms298432 KiB
88Accepted360ms233932 KiB
89Runtime error503ms298404 KiB
90Runtime error479ms298508 KiB
91Runtime error469ms298464 KiB
92Runtime error488ms298248 KiB
93Time limit exceeded1.082s119316 KiB
94Runtime error626ms298276 KiB
95Runtime error518ms298384 KiB
96Runtime error721ms298428 KiB
97Accepted620ms269340 KiB
98Accepted453ms239360 KiB
99Accepted500ms242224 KiB
100Accepted670ms261928 KiB
101Accepted597ms247784 KiB