109502024-04-20 18:29:2242Vállalati ügyeletpypy3Time limit exceeded 70/1001.082s259504 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:
            A[P[i]] |= cur
            #if len(A[P[i]]) >= len(cur):
            #    #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
1Accepted43ms76412 KiB
2Accepted335ms183160 KiB
subtask25/5
3Accepted43ms77080 KiB
4Accepted39ms77516 KiB
5Accepted39ms77432 KiB
6Accepted39ms77776 KiB
subtask38/8
7Accepted43ms77080 KiB
8Accepted39ms77516 KiB
9Accepted39ms77432 KiB
10Accepted39ms77776 KiB
11Accepted179ms177640 KiB
12Accepted180ms173032 KiB
13Accepted185ms177664 KiB
14Accepted216ms186456 KiB
subtask412/12
15Accepted43ms77080 KiB
16Accepted39ms77516 KiB
17Accepted39ms77432 KiB
18Accepted39ms77776 KiB
19Accepted172ms182928 KiB
20Accepted173ms177848 KiB
21Accepted173ms179012 KiB
22Accepted202ms186264 KiB
23Accepted193ms178724 KiB
24Accepted189ms180304 KiB
subtask517/17
25Accepted43ms77080 KiB
26Accepted39ms77516 KiB
27Accepted39ms77432 KiB
28Accepted39ms77776 KiB
29Accepted61ms90552 KiB
30Accepted68ms91180 KiB
31Accepted64ms90400 KiB
32Accepted71ms90900 KiB
33Accepted68ms91312 KiB
34Accepted63ms92100 KiB
35Accepted64ms91808 KiB
36Accepted63ms91808 KiB
37Accepted75ms91976 KiB
38Accepted67ms91644 KiB
39Accepted72ms91884 KiB
40Accepted72ms92068 KiB
41Accepted67ms92168 KiB
subtask628/28
42Accepted323ms180636 KiB
43Accepted514ms183800 KiB
44Accepted657ms183892 KiB
45Accepted505ms180660 KiB
46Accepted368ms182776 KiB
47Accepted234ms180568 KiB
48Accepted216ms182260 KiB
49Accepted203ms188080 KiB
50Accepted194ms180736 KiB
subtask70/30
51Accepted39ms80004 KiB
52Accepted337ms186204 KiB
53Accepted43ms77080 KiB
54Accepted39ms77516 KiB
55Accepted39ms77432 KiB
56Accepted39ms77776 KiB
57Accepted179ms177640 KiB
58Accepted180ms173032 KiB
59Accepted185ms177664 KiB
60Accepted216ms186456 KiB
61Accepted172ms182928 KiB
62Accepted173ms177848 KiB
63Accepted173ms179012 KiB
64Accepted202ms186264 KiB
65Accepted193ms178724 KiB
66Accepted189ms180304 KiB
67Accepted61ms90552 KiB
68Accepted68ms91180 KiB
69Accepted64ms90400 KiB
70Accepted71ms90900 KiB
71Accepted68ms91312 KiB
72Accepted63ms92100 KiB
73Accepted64ms91808 KiB
74Accepted63ms91808 KiB
75Accepted75ms91976 KiB
76Accepted67ms91644 KiB
77Accepted72ms91884 KiB
78Accepted72ms92068 KiB
79Accepted67ms92168 KiB
80Accepted323ms180636 KiB
81Accepted514ms183800 KiB
82Accepted657ms183892 KiB
83Accepted505ms180660 KiB
84Accepted368ms182776 KiB
85Accepted234ms180568 KiB
86Accepted216ms182260 KiB
87Accepted203ms188080 KiB
88Accepted194ms180736 KiB
89Accepted418ms199096 KiB
90Accepted423ms203056 KiB
91Accepted503ms234556 KiB
92Accepted460ms259504 KiB
93Time limit exceeded1.082s82152 KiB
94Time limit exceeded1.065s83296 KiB
95Accepted246ms183724 KiB
96Accepted750ms190448 KiB
97Accepted375ms185764 KiB
98Accepted279ms181504 KiB
99Accepted307ms180184 KiB
100Accepted333ms186360 KiB
101Accepted286ms185896 KiB