No.1488 Max Score of the Tree
Problem Statement
You are given a rooted tree $T$ with $N$ vertices. The vertices of $T$ are numbered from $1$ to $N$, and the root is vertex $1$.
Among the $N-1$ edges of $T$, the $i$-th edge connects vertex $a_i$ and vertex $b_i$ and has length $c_i$.
You can perform the following operation $1$ time on $T$.
- Choose edges so that the sum of their lengths is at most $K$, and multiply the length of each chosen edge by $2$.
The score of $T$ is defined as the sum of the depths of its leaves. Find the maximum score achievable by performing the operation appropriately.
Input
$N\ K$
$a_1\ b_1\ c_1$
$a_2\ b_2\ c_2$
$\vdots$
$a_{N-1}\ b_{N-1}\ c_{N-1}$
- All inputs are integers.
- $2 \le N \le 100$
- $1 \le K \le 10^5$
- $1 \le a_i, b_i\le N$
- $1 \le c_i\le K$
- The given graph is a tree.
Output
Output the maximum achievable score, followed by a newline.
Sample
Sample 1
Input
3 7 2 3 4 2 1 5
Output
14
For example, choosing edge $2$ gives a score of $14$, which is the maximum.
Sample 2
Input
5 16 2 1 2 5 1 2 4 5 13 3 4 3
Output
36
For example, choosing edge $3$ and edge $4$ gives a score of $36$, which is the maximum.
Sample 3
Input
16 57 5 12 18 5 13 11 1 12 57 13 10 19 13 3 4 6 1 47 10 2 13 11 12 6 3 14 1 16 1 39 7 5 4 15 2 16 9 5 48 8 13 43 12 4 41
Output
1202
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
MZKi
maguro