Codeforces Global Round 23

Solutions are presented as using the least memory and the fastest execution time. It also takes the top 10 most recent solutions from each language. If you want to limit to a specific index, click the "Solved" button and go to that problem.

ContestId
Name
Phase
Frozen
Duration (Seconds)
Relative Time
Start Time
1746 Codeforces Global Round 23 FINISHED False 8100 71335463 Oct. 15, 2022, 2:35 p.m.

Problems

Solved$
Index
Name
Type
Tags
Community Tag
Rating
( 4738 ) D Paths on the Tree PROGRAMMING dfs and similar dp greedy sortings trees

B'You are given a rooted tree consisting of n vertices. The vertices are numbered from 1 to n , and the root is the vertex 1 . You are also given a score array s_1, s_2, ldots, s_n . A multiset of k simple paths is called valid if the following two conditions are both true. It can be shown that it is always possible to find at least one valid multiset. Find the maximum value among all valid multisets. Each test contains multiple test cases. The first line contains a single integer t ( 1 <= q t <= q 10^4 ) -- the number of test cases. The description of the test cases follows. The first line of each test case contains two space-separated integers n ( 2 <= n <= 2 cdot 10^5 ) and k ( 1 <= k <= 10^9 ) -- the size of the tree and the required number of paths. The second line contains n - 1 space-separated integers p_2,p_3, ldots,p_n ( 1 <= p_i <= n ), where p_i is the parent of the i -th vertex. It is guaranteed that this value describe a valid tree with root 1 . The third line contains n space-separated integers s_1,s_2, ldots,s_n ( 0 <= s_i <= 10^4 ) -- the scores of the vertices. It is guaranteed that the sum of n over all test cases does not exceed 2 cdot 10 ^ 5 . For each test case, print a single integer -- the maximum value of a path multiset. In the first test case, one of optimal solutions is four paths 1 to 2 to 3 to 5 , 1 to 2 to 3 to 5 , 1 to 4 , 1 to 4 , here c=[4,2,2,2,2] . The value equals to 4 cdot 6+ 2 cdot 2+2 cdot 1+2 cdot 5+2 cdot 7=54 . In the second test case, one of optimal solution is three paths 1 to 2 to 3 to 5 , 1 to 2 to 3 to 5 , 1 to 4 , here c=[3,2,2,1,2] . The value equals to 3 cdot 6+ 2 cdot 6+2 cdot 1+1 cdot 4+2 cdot 10=56 . '...

Tutorials

Codeforces Global Round 23 Editorial

Submissions

Submission Id
Author(s)
Index
Submitted
Verdict
Language
Test Set
Tests Passed
Time taken (ms)
Memory Consumed (bytes)
Tags
Rating
176414809 Tdyx D Oct. 16, 2022, 2:25 a.m. OK C# 8 TESTS 81 468 78336000
176387413 klucse2000031969 D Oct. 15, 2022, 6:20 p.m. OK Clang++17 Diagnostics TESTS 81 1185 267673600

remove filters

Back to search problems