Under construction

Still being built. Things may change

Urban geography

Interview

Time limit2sMemory limit1024 MB

Summary
Pick a set of roads that keeps all districts connected while minimizing the gap between the most expensive and cheapest kept road, then print their numbers.
Level

Medium5 of 10

Topics
Two pointers, Union-find, Sorting, Graph
Solved
No attempts yet

Problem

Android Vasya prepares a project in Urban geography. The aim of the project is to improve the infrastructure of the city he lives in.

Now the city consists of nn districts, some of which are connected by roads. Using these roads one can get from any district to any other district of the city by car. Vasya thinks that such a big amount of roads makes citizens use their own cars instead of walking or cycling. He wants to close as many roads for cars as possible and turn them into boulevards. Of course, Vasya wants to keep the possibility to get from any district to any other district of the city by car using roads.

Now citizens pay for using roads, and prices for different roads may vary a lot. Vasya thinks that leaving open some expensive and some cheap roads at the same time is not a good idea because it can increase social tension in the city. That is why he wants to minimize the price spread between the most expensive and the cheapest roads. Help Vasya choose the roads to keep open.

Input

The first line contains integers nn and mm: the number of city districts and roads, respectively (2≤n≤30 0002 \leq n \leq 30\,000; n−1≤m≤30 000n - 1 \leq m \leq 30\,000). The next mm lines contain triples of integers aia_i, bib_i, and cic_i, meaning that between the city districts aia_i and bib_i there is a road with the price cic_i (1≤ai,bi≤n1 \leq a_i, b_i \leq n; ai≠bia_i \neq b_i; 1≤ci≤1091 \leq c_i \leq 10^9). There can be several roads between two districts.

Output

In the only line, output the sequence of integers: the numbers of the roads which should be kept open in the city. The roads are numbered as they appear in the input data. If there are several solutions, output any of them.

Examples2

  1. Example 1

    Input
    3 3
    1 2 1
    2 3 3
    3 1 4
    
    Expected output
    2 3
    
  2. Example 2

    Input
    4 5
    1 2 1
    2 3 1
    1 3 2
    1 4 2
    2 4 1
    
    Expected output
    1 2 5