109552024-04-20 18:39:0942Vállalati ügyeletpypy3Time limit exceeded 70/1001.07s242356 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)-100:
                #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
1Accepted39ms76348 KiB
2Accepted289ms181556 KiB
subtask25/5
3Accepted48ms77248 KiB
4Accepted46ms77916 KiB
5Accepted46ms77748 KiB
6Accepted43ms78164 KiB
subtask38/8
7Accepted48ms77248 KiB
8Accepted46ms77916 KiB
9Accepted46ms77748 KiB
10Accepted43ms78164 KiB
11Accepted181ms177488 KiB
12Accepted211ms177460 KiB
13Accepted216ms177632 KiB
14Accepted252ms180652 KiB
subtask412/12
15Accepted48ms77248 KiB
16Accepted46ms77916 KiB
17Accepted46ms77748 KiB
18Accepted43ms78164 KiB
19Accepted174ms183536 KiB
20Accepted174ms178196 KiB
21Accepted173ms179728 KiB
22Accepted201ms184516 KiB
23Accepted221ms181992 KiB
24Accepted224ms179604 KiB
subtask517/17
25Accepted48ms77248 KiB
26Accepted46ms77916 KiB
27Accepted46ms77748 KiB
28Accepted43ms78164 KiB
29Accepted71ms91068 KiB
30Accepted63ms91080 KiB
31Accepted68ms91084 KiB
32Accepted72ms91184 KiB
33Accepted79ms91276 KiB
34Accepted68ms91656 KiB
35Accepted74ms91852 KiB
36Accepted71ms91200 KiB
37Accepted65ms91852 KiB
38Accepted76ms91744 KiB
39Accepted79ms92228 KiB
40Accepted72ms92224 KiB
41Accepted71ms92112 KiB
subtask628/28
42Accepted289ms180076 KiB
43Accepted379ms183476 KiB
44Accepted423ms183692 KiB
45Accepted356ms183680 KiB
46Accepted300ms182968 KiB
47Accepted225ms183184 KiB
48Accepted256ms182392 KiB
49Accepted240ms186028 KiB
50Accepted203ms182968 KiB
subtask70/30
51Accepted39ms80172 KiB
52Accepted263ms185348 KiB
53Accepted48ms77248 KiB
54Accepted46ms77916 KiB
55Accepted46ms77748 KiB
56Accepted43ms78164 KiB
57Accepted181ms177488 KiB
58Accepted211ms177460 KiB
59Accepted216ms177632 KiB
60Accepted252ms180652 KiB
61Accepted174ms183536 KiB
62Accepted174ms178196 KiB
63Accepted173ms179728 KiB
64Accepted201ms184516 KiB
65Accepted221ms181992 KiB
66Accepted224ms179604 KiB
67Accepted71ms91068 KiB
68Accepted63ms91080 KiB
69Accepted68ms91084 KiB
70Accepted72ms91184 KiB
71Accepted79ms91276 KiB
72Accepted68ms91656 KiB
73Accepted74ms91852 KiB
74Accepted71ms91200 KiB
75Accepted65ms91852 KiB
76Accepted76ms91744 KiB
77Accepted79ms92228 KiB
78Accepted72ms92224 KiB
79Accepted71ms92112 KiB
80Accepted289ms180076 KiB
81Accepted379ms183476 KiB
82Accepted423ms183692 KiB
83Accepted356ms183680 KiB
84Accepted300ms182968 KiB
85Accepted225ms183184 KiB
86Accepted256ms182392 KiB
87Accepted240ms186028 KiB
88Accepted203ms182968 KiB
89Accepted349ms193376 KiB
90Accepted347ms201156 KiB
91Accepted402ms236160 KiB
92Accepted432ms242356 KiB
93Time limit exceeded1.07s94332 KiB
94Time limit exceeded1.026s91392 KiB
95Accepted272ms187644 KiB
96Accepted474ms219780 KiB
97Accepted275ms185736 KiB
98Accepted243ms181252 KiB
99Accepted266ms179932 KiB
100Accepted272ms179632 KiB
101Accepted239ms185588 KiB