109462024-04-20 18:05:0042Vállalati ügyeletpython3Time limit exceeded 22/1001.105s179428 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]])
    for i in range(1,N+1):
        stdout.write(str(res[i])+' ')
    stdout.write('\n')
        
main()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted18ms11372 KiB
2Accepted984ms162464 KiB
subtask25/5
3Accepted17ms12004 KiB
4Accepted17ms12148 KiB
5Accepted17ms12116 KiB
6Accepted17ms12008 KiB
subtask30/8
7Accepted17ms12004 KiB
8Accepted17ms12148 KiB
9Accepted17ms12116 KiB
10Accepted17ms12008 KiB
11Time limit exceeded1.103s74532 KiB
12Time limit exceeded1.105s75260 KiB
13Time limit exceeded1.067s73680 KiB
14Time limit exceeded1.075s74140 KiB
subtask40/12
15Accepted17ms12004 KiB
16Accepted17ms12148 KiB
17Accepted17ms12116 KiB
18Accepted17ms12008 KiB
19Time limit exceeded1.07s81640 KiB
20Time limit exceeded1.064s81780 KiB
21Time limit exceeded1.08s81872 KiB
22Time limit exceeded1.072s82368 KiB
23Accepted758ms166532 KiB
24Time limit exceeded1.057s82312 KiB
subtask517/17
25Accepted17ms12004 KiB
26Accepted17ms12148 KiB
27Accepted17ms12116 KiB
28Accepted17ms12008 KiB
29Accepted48ms14904 KiB
30Accepted48ms15264 KiB
31Accepted25ms14464 KiB
32Accepted25ms14692 KiB
33Accepted25ms14776 KiB
34Accepted24ms14472 KiB
35Accepted26ms15288 KiB
36Accepted26ms14860 KiB
37Accepted39ms15236 KiB
38Accepted24ms14928 KiB
39Accepted24ms14688 KiB
40Accepted25ms14872 KiB
41Accepted25ms15140 KiB
subtask60/28
42Time limit exceeded1.013s166968 KiB
43Time limit exceeded1.105s82952 KiB
44Time limit exceeded1.065s83028 KiB
45Time limit exceeded1.065s83260 KiB
46Time limit exceeded1.065s83340 KiB
47Time limit exceeded1.105s83332 KiB
48Time limit exceeded1.062s75632 KiB
49Time limit exceeded1.08s83620 KiB
50Accepted805ms168132 KiB
subtask70/30
51Accepted18ms14604 KiB
52Accepted1s165216 KiB
53Accepted17ms12004 KiB
54Accepted17ms12148 KiB
55Accepted17ms12116 KiB
56Accepted17ms12008 KiB
57Time limit exceeded1.103s74532 KiB
58Time limit exceeded1.105s75260 KiB
59Time limit exceeded1.067s73680 KiB
60Time limit exceeded1.075s74140 KiB
61Time limit exceeded1.07s81640 KiB
62Time limit exceeded1.064s81780 KiB
63Time limit exceeded1.08s81872 KiB
64Time limit exceeded1.072s82368 KiB
65Accepted758ms166532 KiB
66Time limit exceeded1.057s82312 KiB
67Accepted48ms14904 KiB
68Accepted48ms15264 KiB
69Accepted25ms14464 KiB
70Accepted25ms14692 KiB
71Accepted25ms14776 KiB
72Accepted24ms14472 KiB
73Accepted26ms15288 KiB
74Accepted26ms14860 KiB
75Accepted39ms15236 KiB
76Accepted24ms14928 KiB
77Accepted24ms14688 KiB
78Accepted25ms14872 KiB
79Accepted25ms15140 KiB
80Time limit exceeded1.013s166968 KiB
81Time limit exceeded1.105s82952 KiB
82Time limit exceeded1.065s83028 KiB
83Time limit exceeded1.065s83260 KiB
84Time limit exceeded1.065s83340 KiB
85Time limit exceeded1.105s83332 KiB
86Time limit exceeded1.062s75632 KiB
87Time limit exceeded1.08s83620 KiB
88Accepted805ms168132 KiB
89Accepted783ms153144 KiB
90Accepted954ms160016 KiB
91Accepted995ms179428 KiB
92Time limit exceeded1.067s98548 KiB
93Time limit exceeded1.085s74136 KiB
94Time limit exceeded1.065s79244 KiB
95Time limit exceeded1.075s84288 KiB
96Time limit exceeded1.07s83608 KiB
97Time limit exceeded1.065s82376 KiB
98Accepted898ms156120 KiB
99Accepted943ms167636 KiB
100Time limit exceeded1.065s82888 KiB
101Time limit exceeded1.047s79840 KiB