#abc252e. E - Road Reduction

E - Road Reduction

Score : 500500 points

问题描述

在AtCoder王国中,有NN个城市,分别称为城市1、2、…、NN,以及MM条道路,分别称为道路1、2、…、MM

道路ii双向连接城市AiA_iBiB_i,长度为CiC_i。借助某些道路,可以从任意两个城市之间通行。

由于财政困难,王国决定仅保留N1N-1条道路,确保使用这些道路仍能从任意两个城市间通行,并放弃其余道路。

did_i表示仅使用维护的道路从城市1到城市ii所需经过的道路总长度。请输出一种道路选择方案,使得d2+d3++dNd_2+d_3+\ldots+d_N的值最小化。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

The Kingdom of AtCoder has NN cities called City 1,2,,N1,2,\ldots,N and MM roads called Road 1,2,,M1,2,\ldots,M.
Road ii connects Cities AiA_i and BiB_i bidirectionally and has a length of CiC_i.
One can travel between any two cities using some roads.

Under financial difficulties, the kingdom has decided to maintain only N1N-1 roads so that one can still travel between any two cities using those roads and abandon the rest.

Let did_i be the total length of the roads one must use when going from City 11 to City ii using only maintained roads. Print a choice of roads to maintain that minimizes d2+d3++dNd_2+d_3+\ldots+d_N.

Constraints

  • 2N2×1052 \leq N \leq 2\times 10^5
  • N1M2×105N-1 \leq M \leq 2\times 10^5
  • 1Ai<BiN1 \leq A_i < B_i \leq N
  • (Ai,Bi)(Aj,Bj)(A_i,B_i)\neq(A_j,B_j) if iji\neq j.
  • 1Ci1091\leq C_i \leq 10^9
  • 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:

NN MM

A1A_1 B1B_1 C1C_1

A2A_2 B2B_2 C2C_2

\vdots

AMA_M BMB_M CMC_M

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 did_i.

  • Maintain Road 11 and 22: d2=1d_2=1, d3=3d_3=3.
  • Maintain Road 11 and 33: d2=1d_2=1, d3=10d_3=10.
  • Maintain Road 22 and 33: d2=12d_2=12, d3=10d_3=10.

Thus, maintaining Road 11 and 22 minimizes d2+d3d_2+d_3.

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