#abc252e. E - Road Reduction
E - Road Reduction
Score : points
问题描述
在AtCoder王国中,有个城市,分别称为城市1、2、…、,以及条道路,分别称为道路1、2、…、。
道路双向连接城市和,长度为。借助某些道路,可以从任意两个城市之间通行。
由于财政困难,王国决定仅保留条道路,确保使用这些道路仍能从任意两个城市间通行,并放弃其余道路。
令表示仅使用维护的道路从城市1到城市所需经过的道路总长度。请输出一种道路选择方案,使得的值最小化。
以上为通义千问 qwen-max 翻译,仅供参考。
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.
Sample Input 1
3 3
1 2 1
2 3 2
1 3 10
Sample Output 1
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 .
Sample Input 2
4 6
1 2 1
1 3 1
1 4 1
2 3 1
2 4 1
3 4 1
Sample Output 2
3 1 2
update @ 2024/3/10 10:45:47