Task: | Tree game |
Sender: | louaha1 |
Submission time: | 2024-10-07 17:42:47 +0300 |
Language: | Python3 (CPython3) |
Status: | READY |
Result: | WRONG ANSWER |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.02 s | details |
#2 | WRONG ANSWER | 0.02 s | details |
#3 | WRONG ANSWER | 0.02 s | details |
#4 | WRONG ANSWER | 0.02 s | details |
#5 | WRONG ANSWER | 0.02 s | details |
#6 | WRONG ANSWER | 0.02 s | details |
#7 | WRONG ANSWER | 0.02 s | details |
#8 | WRONG ANSWER | 0.02 s | details |
#9 | WRONG ANSWER | 0.02 s | details |
#10 | WRONG ANSWER | 0.02 s | details |
#11 | WRONG ANSWER | 0.02 s | details |
#12 | WRONG ANSWER | 0.02 s | details |
#13 | WRONG ANSWER | 0.02 s | details |
#14 | WRONG ANSWER | 0.02 s | details |
#15 | WRONG ANSWER | 0.02 s | details |
#16 | WRONG ANSWER | 0.02 s | details |
#17 | WRONG ANSWER | 0.02 s | details |
#18 | WRONG ANSWER | 0.02 s | details |
#19 | WRONG ANSWER | 0.02 s | details |
#20 | WRONG ANSWER | 0.02 s | details |
#21 | WRONG ANSWER | 0.02 s | details |
#22 | WRONG ANSWER | 0.02 s | details |
#23 | WRONG ANSWER | 0.02 s | details |
#24 | WRONG ANSWER | 0.02 s | details |
#25 | WRONG ANSWER | 0.02 s | details |
#26 | WRONG ANSWER | 0.02 s | details |
#27 | WRONG ANSWER | 0.02 s | details |
#28 | WRONG ANSWER | 0.02 s | details |
#29 | WRONG ANSWER | 0.02 s | details |
#30 | WRONG ANSWER | 0.02 s | details |
#31 | WRONG ANSWER | 0.02 s | details |
#32 | WRONG ANSWER | 0.02 s | details |
#33 | WRONG ANSWER | 0.02 s | details |
#34 | WRONG ANSWER | 0.02 s | details |
#35 | WRONG ANSWER | 0.02 s | details |
#36 | WRONG ANSWER | 0.02 s | details |
#37 | WRONG ANSWER | 0.02 s | details |
#38 | WRONG ANSWER | 0.02 s | details |
#39 | WRONG ANSWER | 0.02 s | details |
#40 | WRONG ANSWER | 0.02 s | details |
#41 | WRONG ANSWER | 0.02 s | details |
#42 | WRONG ANSWER | 0.02 s | details |
#43 | WRONG ANSWER | 0.02 s | details |
#44 | WRONG ANSWER | 0.02 s | details |
#45 | WRONG ANSWER | 0.02 s | details |
#46 | WRONG ANSWER | 0.02 s | details |
#47 | WRONG ANSWER | 0.02 s | details |
#48 | WRONG ANSWER | 0.02 s | details |
#49 | WRONG ANSWER | 0.02 s | details |
#50 | WRONG ANSWER | 0.02 s | details |
#51 | WRONG ANSWER | 0.02 s | details |
#52 | WRONG ANSWER | 0.02 s | details |
#53 | WRONG ANSWER | 0.02 s | details |
#54 | WRONG ANSWER | 0.02 s | details |
#55 | WRONG ANSWER | 0.02 s | details |
#56 | WRONG ANSWER | 0.02 s | details |
#57 | WRONG ANSWER | 0.02 s | details |
#58 | WRONG ANSWER | 0.02 s | details |
#59 | WRONG ANSWER | 0.02 s | details |
#60 | WRONG ANSWER | 0.19 s | details |
#61 | WRONG ANSWER | 0.26 s | details |
#62 | WRONG ANSWER | 0.25 s | details |
#63 | WRONG ANSWER | 0.19 s | details |
#64 | WRONG ANSWER | 0.22 s | details |
#65 | WRONG ANSWER | 0.26 s | details |
#66 | WRONG ANSWER | 0.25 s | details |
#67 | WRONG ANSWER | 0.25 s | details |
#68 | WRONG ANSWER | 0.20 s | details |
#69 | WRONG ANSWER | 0.21 s | details |
Code
from collections import defaultdict import sys sys.setrecursionlimit(200000) def dfs(node, tree, points): # Base case: If node is a leaf, return its points if node not in tree: return points[node] # List to store the maximum points Uolevi can collect from each subtree subtree_scores = [] # Traverse all children of the current node for child in tree[node]: subtree_scores.append(dfs(child, tree, points)) # Maija will cut all but the maximum subtree if subtree_scores: return points[node] + max(subtree_scores) return points[node] def solve(): n = int(input()) # Number of nodes points = list(map(int, input().split())) # Points on each node parents = list(map(int, input().split())) # Parent of each node # Build the tree using an adjacency list tree = defaultdict(list) for i in range(1, n): tree[parents[i] - 1].append(i) # 0-indexed parent-child relationship # Perform DFS starting from the root (node 0) result = dfs(0, tree, points) print(result) # Test the function with input: solve()
Test details
Test 1
Verdict: ACCEPTED
input |
---|
1 8 1 |
correct output |
---|
8 |
user output |
---|
8 |
Test 2
Verdict: WRONG ANSWER
input |
---|
2 8 8 1 1 |
correct output |
---|
8 |
user output |
---|
16 |
Test 3
Verdict: WRONG ANSWER
input |
---|
3 3 1 6 1 3 1 |
correct output |
---|
3 |
user output |
---|
10 |
Test 4
Verdict: WRONG ANSWER
input |
---|
3 5 8 4 1 1 2 |
correct output |
---|
5 |
user output |
---|
17 |
Test 5
Verdict: WRONG ANSWER
input |
---|
3 8 8 3 1 1 1 |
correct output |
---|
11 |
user output |
---|
16 |
Test 6
Verdict: WRONG ANSWER
input |
---|
4 9 8 1 6 1 1 2 2 |
correct output |
---|
9 |
user output |
---|
23 |
Test 7
Verdict: WRONG ANSWER
input |
---|
4 10 1 4 3 1 1 1 2 |
correct output |
---|
11 |
user output |
---|
14 |
Test 8
Verdict: WRONG ANSWER
input |
---|
4 9 10 2 6 1 4 1 1 |
correct output |
---|
11 |
user output |
---|
25 |
Test 9
Verdict: WRONG ANSWER
input |
---|
4 7 4 9 2 1 1 1 3 |
correct output |
---|
11 |
user output |
---|
18 |
Test 10
Verdict: WRONG ANSWER
input |
---|
5 9 5 7 7 4 1 1 4 2 4 |
correct output |
---|
9 |
user output |
---|
28 |
Test 11
Verdict: WRONG ANSWER
input |
---|
5 10 2 3 1 4 1 1 1 1 3 |
correct output |
---|
12 |
user output |
---|
17 |
Test 12
Verdict: WRONG ANSWER
input |
---|
5 5 5 4 4 2 1 4 4 1 2 |
correct output |
---|
5 |
user output |
---|
16 |
Test 13
Verdict: WRONG ANSWER
input |
---|
5 6 9 5 9 1 1 1 1 3 1 |
correct output |
---|
11 |
user output |
---|
20 |
Test 14
Verdict: WRONG ANSWER
input |
---|
5 7 7 6 3 2 1 1 2 3 3 |
correct output |
---|
7 |
user output |
---|
23 |
Test 15
Verdict: WRONG ANSWER
input |
---|
5 10 5 1 7 4 1 1 5 3 1 |
correct output |
---|
14 |
user output |
---|
22 |
Test 16
Verdict: WRONG ANSWER
input |
---|
5 4 2 10 6 1 1 1 2 1 1 |
correct output |
---|
6 |
user output |
---|
16 |
Test 17
Verdict: WRONG ANSWER
input |
---|
5 5 10 4 6 3 1 1 2 1 2 |
correct output |
---|
11 |
user output |
---|
19 |
Test 18
Verdict: WRONG ANSWER
input |
---|
5 9 3 5 1 7 1 5 5 3 1 |
correct output |
---|
9 |
user output |
---|
22 |
Test 19
Verdict: WRONG ANSWER
input |
---|
5 4 2 1 3 9 1 1 1 1 1 |
correct output |
---|
7 |
user output |
---|
13 |
Test 20
Verdict: WRONG ANSWER
input |
---|
10 9 1 10 3 4 5 8 9 6 5 1 4 2 1 7 4 8 6 7 8 |
correct output |
---|
9 |
user output |
---|
40 |
Test 21
Verdict: WRONG ANSWER
input |
---|
10 4 7 4 10 6 9 5 4 7 6 1 1 1 2 1 1 8 2 3 3 |
correct output |
---|
14 |
user output |
---|
21 |
Test 22
Verdict: WRONG ANSWER
input |
---|
10 7 2 3 5 3 7 7 9 6 7 1 8 2 7 8 7 1 1 6 7 |
correct output |
---|
18 |
user output |
---|
27 |
Test 23
Verdict: WRONG ANSWER
input |
---|
10 3 3 1 1 5 7 1 2 5 5 1 5 7 2 1 5 8 5 1 1 |
correct output |
---|
8 |
user output |
---|
15 |
Test 24
Verdict: WRONG ANSWER
input |
---|
10 1 7 3 10 5 7 8 1 2 6 1 1 1 2 9 2 9 3 2 9 |
correct output |
---|
4 |
user output |
---|
18 |
Test 25
Verdict: WRONG ANSWER
input |
---|
10 6 5 3 10 2 9 1 7 8 9 1 8 5 1 1 10 2 5 8 2 |
correct output |
---|
11 |
user output |
---|
38 |
Test 26
Verdict: WRONG ANSWER
input |
---|
10 5 6 4 5 7 9 5 8 8 4 1 1 4 2 6 1 6 5 1 1 |
correct output |
---|
13 |
user output |
---|
29 |
Test 27
Verdict: WRONG ANSWER
input |
---|
10 1 5 3 1 5 6 7 9 9 4 1 5 10 9 1 9 9 4 5 5 |
correct output |
---|
1 |
user output |
---|
25 |
Test 28
Verdict: WRONG ANSWER
input |
---|
10 5 5 6 9 5 10 6 2 6 8 1 1 4 9 9 1 2 1 6 8 |
correct output |
---|
10 |
user output |
---|
36 |
Test 29
Verdict: WRONG ANSWER
input |
---|
10 3 2 1 4 4 5 2 4 9 4 1 5 1 2 1 1 3 1 1 9 |
correct output |
---|
8 |
user output |
---|
16 |
Test 30
Verdict: WRONG ANSWER
input |
---|
100 21461600 42077569 474283491 30... |
correct output |
---|
966865392 |
user output |
---|
8700460630 |
Test 31
Verdict: WRONG ANSWER
input |
---|
100 578129114 177547714 700400588 ... |
correct output |
---|
1855515684 |
user output |
---|
6859758335 |
Test 32
Verdict: WRONG ANSWER
input |
---|
100 994871996 791076134 5953277 40... |
correct output |
---|
1814515836 |
user output |
---|
18446045869 |
Test 33
Verdict: WRONG ANSWER
input |
---|
100 222228197 71907871 993998009 7... |
correct output |
---|
1135951805 |
user output |
---|
5247175418 |
Test 34
Verdict: WRONG ANSWER
input |
---|
100 579900832 174882180 138713252 ... |
correct output |
---|
716202927 |
user output |
---|
19322873339 |
Test 35
Verdict: WRONG ANSWER
input |
---|
100 189754281 378059061 342381828 ... |
correct output |
---|
1551273774 |
user output |
---|
6100638661 |
Test 36
Verdict: WRONG ANSWER
input |
---|
100 915344 434975452 466660908 159... |
correct output |
---|
907612293 |
user output |
---|
18591823534 |
Test 37
Verdict: WRONG ANSWER
input |
---|
100 857806942 521650866 432061350 ... |
correct output |
---|
2316691892 |
user output |
---|
8067198204 |
Test 38
Verdict: WRONG ANSWER
input |
---|
100 126184681 630426411 840357157 ... |
correct output |
---|
126184681 |
user output |
---|
17083582751 |
Test 39
Verdict: WRONG ANSWER
input |
---|
100 877496128 782849725 556141400 ... |
correct output |
---|
2248009755 |
user output |
---|
7185252882 |
Test 40
Verdict: WRONG ANSWER
input |
---|
200 903167338 160468896 971358120 ... |
correct output |
---|
2615788195 |
user output |
---|
8129545985 |
Test 41
Verdict: WRONG ANSWER
input |
---|
200 139339061 77281799 316066077 3... |
correct output |
---|
729411647 |
user output |
---|
33780838779 |
Test 42
Verdict: WRONG ANSWER
input |
---|
200 19617302 94019529 17298266 328... |
correct output |
---|
983806343 |
user output |
---|
8395563166 |
Test 43
Verdict: WRONG ANSWER
input |
---|
200 578170987 336960706 697473976 ... |
correct output |
---|
1901938137 |
user output |
---|
5321200028 |
Test 44
Verdict: WRONG ANSWER
input |
---|
200 956690801 79083637 339599313 1... |
correct output |
---|
1857249559 |
user output |
---|
4916587904 |
Test 45
Verdict: WRONG ANSWER
input |
---|
200 185716349 143762158 115416001 ... |
correct output |
---|
1057534782 |
user output |
---|
34665638168 |
Test 46
Verdict: WRONG ANSWER
input |
---|
200 275288896 20815354 254338864 6... |
correct output |
---|
1267445164 |
user output |
---|
9582694143 |
Test 47
Verdict: WRONG ANSWER
input |
---|
200 24900465 555962124 563413635 3... |
correct output |
---|
747057370 |
user output |
---|
5695738959 |
Test 48
Verdict: WRONG ANSWER
input |
---|
200 513524772 254574588 366558027 ... |
correct output |
---|
2272884295 |
user output |
---|
5698653192 |
Test 49
Verdict: WRONG ANSWER
input |
---|
200 490774594 733870697 844510835 ... |
correct output |
---|
1650288517 |
user output |
---|
8410728641 |
Test 50
Verdict: WRONG ANSWER
input |
---|
1000 861884121 322555995 898039039 ... |
correct output |
---|
2972059986 |
user output |
---|
9731141518 |
Test 51
Verdict: WRONG ANSWER
input |
---|
1000 659913933 513100418 571680180 ... |
correct output |
---|
659913933 |
user output |
---|
170287769080 |
Test 52
Verdict: WRONG ANSWER
input |
---|
1000 209874718 348676066 464074417 ... |
correct output |
---|
899398937 |
user output |
---|
167365300592 |
Test 53
Verdict: WRONG ANSWER
input |
---|
1000 645792798 158522181 659799184 ... |
correct output |
---|
2154979899 |
user output |
---|
30936940762 |
Test 54
Verdict: WRONG ANSWER
input |
---|
1000 859348061 421675209 599301462 ... |
correct output |
---|
2387245650 |
user output |
---|
9747249686 |
Test 55
Verdict: WRONG ANSWER
input |
---|
1000 226879800 528482225 208763773 ... |
correct output |
---|
1424568237 |
user output |
---|
35870299059 |
Test 56
Verdict: WRONG ANSWER
input |
---|
1000 233113004 975537019 524093912 ... |
correct output |
---|
1182124106 |
user output |
---|
9443588207 |
Test 57
Verdict: WRONG ANSWER
input |
---|
1000 874049734 75947226 679836952 6... |
correct output |
---|
2874667578 |
user output |
---|
8830726652 |
Test 58
Verdict: WRONG ANSWER
input |
---|
1000 136403860 348337953 506386641 ... |
correct output |
---|
136403860 |
user output |
---|
174566453996 |
Test 59
Verdict: WRONG ANSWER
input |
---|
1000 824089343 410028787 814008876 ... |
correct output |
---|
1778275291 |
user output |
---|
32671151259 |
Test 60
Verdict: WRONG ANSWER
input |
---|
100000 106979616 574727912 291579092 ... |
correct output |
---|
3411435693 |
user output |
---|
15828874719 |
Test 61
Verdict: WRONG ANSWER
input |
---|
100000 834972396 341945130 512367317 ... |
correct output |
---|
1494272515 |
user output |
---|
16764885376153 |
Test 62
Verdict: WRONG ANSWER
input |
---|
100000 964109644 356056141 521072685 ... |
correct output |
---|
1283227450 |
user output |
---|
16634180199386 |
Test 63
Verdict: WRONG ANSWER
input |
---|
100000 779580014 612148564 793692717 ... |
correct output |
---|
4717954657 |
user output |
---|
15744950106 |
Test 64
Verdict: WRONG ANSWER
input |
---|
100000 124576659 286156851 307400435 ... |
correct output |
---|
124576659 |
user output |
---|
3048806724468 |
Test 65
Verdict: WRONG ANSWER
input |
---|
100000 452020023 593221033 326082759 ... |
correct output |
---|
1178920108 |
user output |
---|
16761119774099 |
Test 66
Verdict: WRONG ANSWER
input |
---|
100000 378587281 1836202 116838722 72... |
correct output |
---|
587215770 |
user output |
---|
16654234710319 |
Test 67
Verdict: WRONG ANSWER
input |
---|
100000 877997603 741843452 187099247 ... |
correct output |
---|
1018714881 |
user output |
---|
16565859847979 |
Test 68
Verdict: WRONG ANSWER
input |
---|
100000 280774790 48087557 668312713 4... |
correct output |
---|
3930265099 |
user output |
---|
14394045225 |
Test 69
Verdict: WRONG ANSWER
input |
---|
100000 866596482 430317267 394041807 ... |
correct output |
---|
1639137122 |
user output |
---|
3094446854375 |