109472024-04-20 18:15:4642Vállalati ügyeletpython3Time limit exceeded 34/1001.077s105172 KiB
from sys import stdin, stdout
input=stdin.readline

def main():
    N = int(input())
    P = [0]+list(map(int, input().split()))
    A = [0]+[int(x) for x in 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)
            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
1Accepted18ms11408 KiB
2Accepted713ms73564 KiB
subtask25/5
3Accepted18ms11812 KiB
4Accepted17ms11916 KiB
5Accepted18ms12232 KiB
6Accepted17ms12204 KiB
subtask30/8
7Accepted18ms11812 KiB
8Accepted17ms11916 KiB
9Accepted18ms12232 KiB
10Accepted17ms12204 KiB
11Time limit exceeded1.059s30328 KiB
12Time limit exceeded1.06s30852 KiB
13Time limit exceeded1.065s29288 KiB
14Time limit exceeded1.065s29884 KiB
subtask412/12
15Accepted18ms11812 KiB
16Accepted17ms11916 KiB
17Accepted18ms12232 KiB
18Accepted17ms12204 KiB
19Accepted432ms76948 KiB
20Accepted423ms77260 KiB
21Accepted460ms77744 KiB
22Accepted526ms80348 KiB
23Accepted458ms78544 KiB
24Accepted439ms78244 KiB
subtask517/17
25Accepted18ms11812 KiB
26Accepted17ms11916 KiB
27Accepted18ms12232 KiB
28Accepted17ms12204 KiB
29Accepted46ms14676 KiB
30Accepted21ms15444 KiB
31Accepted21ms14972 KiB
32Accepted23ms15268 KiB
33Accepted24ms15292 KiB
34Accepted23ms15460 KiB
35Accepted24ms15768 KiB
36Accepted23ms15264 KiB
37Accepted23ms15800 KiB
38Accepted23ms15460 KiB
39Accepted23ms15388 KiB
40Accepted23ms15524 KiB
41Accepted21ms15288 KiB
subtask60/28
42Accepted816ms79300 KiB
43Time limit exceeded1.062s39644 KiB
44Time limit exceeded1.077s39608 KiB
45Time limit exceeded1.077s39548 KiB
46Time limit exceeded1.049s39704 KiB
47Accepted568ms79524 KiB
48Time limit exceeded1.057s31892 KiB
49Accepted519ms81624 KiB
50Accepted456ms79572 KiB
subtask70/30
51Accepted17ms15312 KiB
52Accepted726ms76876 KiB
53Accepted18ms11812 KiB
54Accepted17ms11916 KiB
55Accepted18ms12232 KiB
56Accepted17ms12204 KiB
57Time limit exceeded1.059s30328 KiB
58Time limit exceeded1.06s30852 KiB
59Time limit exceeded1.065s29288 KiB
60Time limit exceeded1.065s29884 KiB
61Accepted432ms76948 KiB
62Accepted423ms77260 KiB
63Accepted460ms77744 KiB
64Accepted526ms80348 KiB
65Accepted458ms78544 KiB
66Accepted439ms78244 KiB
67Accepted46ms14676 KiB
68Accepted21ms15444 KiB
69Accepted21ms14972 KiB
70Accepted23ms15268 KiB
71Accepted24ms15292 KiB
72Accepted23ms15460 KiB
73Accepted24ms15768 KiB
74Accepted23ms15264 KiB
75Accepted23ms15800 KiB
76Accepted23ms15460 KiB
77Accepted23ms15388 KiB
78Accepted23ms15524 KiB
79Accepted21ms15288 KiB
80Accepted816ms79300 KiB
81Time limit exceeded1.062s39644 KiB
82Time limit exceeded1.077s39608 KiB
83Time limit exceeded1.077s39548 KiB
84Time limit exceeded1.049s39704 KiB
85Accepted568ms79524 KiB
86Time limit exceeded1.057s31892 KiB
87Accepted519ms81624 KiB
88Accepted456ms79572 KiB
89Accepted663ms83832 KiB
90Accepted726ms92256 KiB
91Accepted855ms105172 KiB
92Accepted890ms103896 KiB
93Time limit exceeded1.054s30584 KiB
94Time limit exceeded1.07s34688 KiB
95Accepted632ms91548 KiB
96Accepted978ms78696 KiB
97Accepted739ms75780 KiB
98Accepted563ms66812 KiB
99Accepted698ms78964 KiB
100Accepted880ms77020 KiB
101Accepted591ms70996 KiB