atcoder#ABC252E. [ABC252E] Road Reduction
[ABC252E] Road Reduction
Score : points
Problem Statement
The Kingdom of AtCoder has cities called City and roads called Road . Road connects Cities and bidirectionally and has a length of . One can travel between any two cities using some roads.
Under financial difficulties, the kingdom has decided to maintain only roads so that one can still travel between any two cities using those roads and abandon the rest.
Let be the total length of the roads one must use when going from City to City using only maintained roads. Print a choice of roads to maintain that minimizes .
Constraints
- if .
- One can travel between any two cities using some roads.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
Print the indices of roads to maintain, in arbitrary order, with spaces in between. If multiple solutions exist, you may print any of them.
3 3
1 2 1
2 3 2
1 3 10
1 2
Here are the possible choices of roads to maintain and the corresponding values of .
- Maintain Road and : , .
- Maintain Road and : , .
- Maintain Road and : , .
Thus, maintaining Road and minimizes .
4 6
1 2 1
1 3 1
1 4 1
2 3 1
2 4 1
3 4 1
3 1 2