#P4149. [IOI 2011] Race
[IOI 2011] Race
Description
Given a tree with a weight on each edge, find a simple path whose total weight equals , with the minimum possible number of edges.
Input Format
The first line contains two integers , representing the number of vertices in the tree and the target path sum.
Each of the next lines contains three integers , representing an undirected edge between and with weight .
Note: vertices are numbered starting from .
Output Format
Output a single integer, the minimal number of edges.
If no such path exists, output .
4 3
0 1 1
1 2 2
1 3 4
2
Hint
For of the testdata, it is guaranteed that , , .
Translated by ChatGPT 5
京公网安备 11011102002149号