109452024-04-20 18:04:5042Vállalati ügyeletpypy3Runtime error 22/1001.088s301580 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
1Accepted39ms76288 KiB
2Accepted460ms236832 KiB
subtask25/5
3Accepted39ms76988 KiB
4Accepted39ms77124 KiB
5Accepted39ms76868 KiB
6Accepted39ms77428 KiB
subtask30/8
7Accepted39ms76988 KiB
8Accepted39ms77124 KiB
9Accepted39ms76868 KiB
10Accepted39ms77428 KiB
11Runtime error787ms301580 KiB
12Runtime error911ms301564 KiB
13Time limit exceeded1.088s130504 KiB
14Runtime error514ms301152 KiB
subtask40/12
15Accepted39ms76988 KiB
16Accepted39ms77124 KiB
17Accepted39ms76868 KiB
18Accepted39ms77428 KiB
19Runtime error759ms300752 KiB
20Runtime error887ms300536 KiB
21Time limit exceeded1.024s127456 KiB
22Runtime error532ms300148 KiB
23Accepted337ms231352 KiB
24Runtime error746ms299864 KiB
subtask517/17
25Accepted39ms76988 KiB
26Accepted39ms77124 KiB
27Accepted39ms76868 KiB
28Accepted39ms77428 KiB
29Accepted78ms93616 KiB
30Accepted74ms92908 KiB
31Accepted64ms92276 KiB
32Accepted65ms92360 KiB
33Accepted71ms92692 KiB
34Accepted74ms91980 KiB
35Accepted68ms92296 KiB
36Accepted68ms92584 KiB
37Accepted79ms92644 KiB
38Accepted76ms92792 KiB
39Accepted79ms94096 KiB
40Accepted74ms93280 KiB
41Accepted70ms92500 KiB
subtask60/28
42Accepted517ms268680 KiB
43Accepted754ms274036 KiB
44Time limit exceeded1.08s119984 KiB
45Time limit exceeded1.064s120244 KiB
46Time limit exceeded1.072s119424 KiB
47Time limit exceeded1.042s111912 KiB
48Runtime error560ms298544 KiB
49Runtime error529ms298604 KiB
50Accepted379ms233564 KiB
subtask70/30
51Accepted39ms80800 KiB
52Accepted472ms240840 KiB
53Accepted39ms76988 KiB
54Accepted39ms77124 KiB
55Accepted39ms76868 KiB
56Accepted39ms77428 KiB
57Runtime error787ms301580 KiB
58Runtime error911ms301564 KiB
59Time limit exceeded1.088s130504 KiB
60Runtime error514ms301152 KiB
61Runtime error759ms300752 KiB
62Runtime error887ms300536 KiB
63Time limit exceeded1.024s127456 KiB
64Runtime error532ms300148 KiB
65Accepted337ms231352 KiB
66Runtime error746ms299864 KiB
67Accepted78ms93616 KiB
68Accepted74ms92908 KiB
69Accepted64ms92276 KiB
70Accepted65ms92360 KiB
71Accepted71ms92692 KiB
72Accepted74ms91980 KiB
73Accepted68ms92296 KiB
74Accepted68ms92584 KiB
75Accepted79ms92644 KiB
76Accepted76ms92792 KiB
77Accepted79ms94096 KiB
78Accepted74ms93280 KiB
79Accepted70ms92500 KiB
80Accepted517ms268680 KiB
81Accepted754ms274036 KiB
82Time limit exceeded1.08s119984 KiB
83Time limit exceeded1.064s120244 KiB
84Time limit exceeded1.072s119424 KiB
85Time limit exceeded1.042s111912 KiB
86Runtime error560ms298544 KiB
87Runtime error529ms298604 KiB
88Accepted379ms233564 KiB
89Runtime error602ms298612 KiB
90Runtime error578ms298592 KiB
91Runtime error485ms298516 KiB
92Runtime error501ms298464 KiB
93Time limit exceeded1.085s119208 KiB
94Runtime error563ms298528 KiB
95Runtime error518ms298480 KiB
96Runtime error610ms298332 KiB
97Accepted619ms255716 KiB
98Accepted490ms232016 KiB
99Accepted435ms233200 KiB
100Accepted638ms247652 KiB
101Accepted578ms235252 KiB