109422024-04-20 17:56:0542Vállalati ügyeletpython3Time limit exceeded 22/1001.105s167708 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
1Accepted17ms10968 KiB
2Accepted915ms162440 KiB
subtask25/5
3Accepted18ms11700 KiB
4Accepted17ms12164 KiB
5Accepted17ms11856 KiB
6Accepted17ms11856 KiB
subtask30/8
7Accepted18ms11700 KiB
8Accepted17ms12164 KiB
9Accepted17ms11856 KiB
10Accepted17ms11856 KiB
11Time limit exceeded1.103s74436 KiB
12Time limit exceeded1.032s75080 KiB
13Time limit exceeded1.059s73716 KiB
14Time limit exceeded1.064s74324 KiB
subtask40/12
15Accepted18ms11700 KiB
16Accepted17ms12164 KiB
17Accepted17ms11856 KiB
18Accepted17ms11856 KiB
19Time limit exceeded1.075s82024 KiB
20Time limit exceeded1.075s82144 KiB
21Time limit exceeded1.072s82472 KiB
22Time limit exceeded1.059s82728 KiB
23Accepted736ms166844 KiB
24Time limit exceeded1.046s82496 KiB
subtask517/17
25Accepted18ms11700 KiB
26Accepted17ms12164 KiB
27Accepted17ms11856 KiB
28Accepted17ms11856 KiB
29Accepted46ms15084 KiB
30Accepted48ms15424 KiB
31Accepted24ms15456 KiB
32Accepted24ms14872 KiB
33Accepted24ms14996 KiB
34Accepted23ms14860 KiB
35Accepted25ms15204 KiB
36Accepted25ms14872 KiB
37Accepted37ms15364 KiB
38Accepted23ms15076 KiB
39Accepted23ms14980 KiB
40Accepted24ms15252 KiB
41Accepted23ms14988 KiB
subtask60/28
42Accepted992ms166984 KiB
43Time limit exceeded1.067s82836 KiB
44Time limit exceeded1.065s83136 KiB
45Time limit exceeded1.052s83060 KiB
46Time limit exceeded1.042s83420 KiB
47Time limit exceeded1.072s83348 KiB
48Time limit exceeded1.07s75528 KiB
49Time limit exceeded1.105s83452 KiB
50Accepted731ms167580 KiB
subtask70/30
51Accepted17ms14276 KiB
52Time limit exceeded1.006s165088 KiB
53Accepted18ms11700 KiB
54Accepted17ms12164 KiB
55Accepted17ms11856 KiB
56Accepted17ms11856 KiB
57Time limit exceeded1.103s74436 KiB
58Time limit exceeded1.032s75080 KiB
59Time limit exceeded1.059s73716 KiB
60Time limit exceeded1.064s74324 KiB
61Time limit exceeded1.075s82024 KiB
62Time limit exceeded1.075s82144 KiB
63Time limit exceeded1.072s82472 KiB
64Time limit exceeded1.059s82728 KiB
65Accepted736ms166844 KiB
66Time limit exceeded1.046s82496 KiB
67Accepted46ms15084 KiB
68Accepted48ms15424 KiB
69Accepted24ms15456 KiB
70Accepted24ms14872 KiB
71Accepted24ms14996 KiB
72Accepted23ms14860 KiB
73Accepted25ms15204 KiB
74Accepted25ms14872 KiB
75Accepted37ms15364 KiB
76Accepted23ms15076 KiB
77Accepted23ms14980 KiB
78Accepted24ms15252 KiB
79Accepted23ms14988 KiB
80Accepted992ms166984 KiB
81Time limit exceeded1.067s82836 KiB
82Time limit exceeded1.065s83136 KiB
83Time limit exceeded1.052s83060 KiB
84Time limit exceeded1.042s83420 KiB
85Time limit exceeded1.072s83348 KiB
86Time limit exceeded1.07s75528 KiB
87Time limit exceeded1.105s83452 KiB
88Accepted731ms167580 KiB
89Accepted889ms152588 KiB
90Accepted808ms159860 KiB
91Time limit exceeded1.085s91628 KiB
92Time limit exceeded1.082s98120 KiB
93Time limit exceeded1.077s74044 KiB
94Time limit exceeded1.044s79192 KiB
95Time limit exceeded1.093s84064 KiB
96Time limit exceeded1.085s83620 KiB
97Time limit exceeded1.064s82492 KiB
98Accepted841ms156036 KiB
99Accepted943ms167708 KiB
100Time limit exceeded1.065s82692 KiB
101Time limit exceeded1.062s79844 KiB