#ABC252E. [ABC252E] Road Reduction

[ABC252E] Road Reduction

Score : 500500 points

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.

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

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