#P11322. Minimum Fire Stations in the Mouse Kingdom

    ID: 13399 Type: Default 1000ms 256MiB

Minimum Fire Stations in the Mouse Kingdom

Minimum Fire Stations in the Mouse Kingdom

In the mouse kingdom there are \(N\) towns numbered from 1 to \(N\), connected by \(N-1\) bidirectional roads. Each road connects two towns and may have a different length. The network is connected, i.e. any two towns can be reached by some sequence of roads.

To effectively extinguish fires, the king's advisor requires that the distance from any fire occurrence to the nearest fire station should not exceed \(K\) kilometers; otherwise the fire would be hard to control. However, building a fire station is expensive. The king wants to minimize the number of fire stations.

Your task is to choose a set of towns in which to build fire stations so that every town is within \(K\) kilometers of at least one fire station, and the total number of fire stations is minimized. If there are multiple solutions, any one is acceptable.

Input Format: The first line contains two integers \(N\) and \(K\) (\(1 \leq N \leq 10^5\), \(0 \leq K \leq 10^9\)). Each of the next \(N-1\) lines contains three integers \(u\), \(v\) and \(w\) indicating that there is a road between towns \(u\) and \(v\) with length \(w\) kilometers (\(1 \leq w \leq 10^9\)).

Output Format: On the first line, output a single integer denoting the minimum number of fire stations. On the second line, output the indices of the towns where fire stations are built, in ascending order separated by spaces.

inputFormat

The first line contains two integers \(N\) and \(K\).

Each of the following \(N-1\) lines contains three integers: \(u\), \(v\), and \(w\), representing a road between towns \(u\) and \(v\) with length \(w\).

outputFormat

The first line should contain the minimum number of fire stations required.

The second line should list the indices of the towns where the fire stations are built, in ascending order and separated by spaces.

sample

4 1
1 2 1
2 3 1
3 4 1
2

1 3

</p>