問題一覧 > 通常問題

No.1488 Max Score of the Tree

レベル : / AI推定難易度 : 1050 / 実行時間制限 : 1ケース 2.000秒 / メモリ制限 : 512 MB / 標準ジャッジ問題
タグ : (AC するまで非表示) / 解いたユーザー数 143
作問者 : MZKi / テスター : maguro
お気に入りにしたユーザー ProblemId : 6237 / 自分の提出
問題文最終更新日: 2023-03-09 19:13:00
This statement was translated by AI (claude-opus-5-5, effort medium) and may contain errors or differ in nuance from the original. The original statement takes precedence. Back to the original
yukicoder contest 292 (順位表) の他の問題:

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もしくは右上の雲マークをクリックしてアカウントを作成してください。