Urban geography

시간 제한2초메모리 제한1024 MB

요약
연결 가중 그래프에서 최대 간선 가중치와 최소 간선 가중치의 차이가 가장 작은 신장 트리를 골라 간선 번호를 출력한다.
난이도

보통10점 중 7점

유형
최소 신장 트리, 정렬, 그리디, 유니온 파인드
정답자
아직 제출이 없습니다

문제

Android Vasya prepares a project in Urban geography. The aim of the project is to improve the infrasructure 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 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 very much. Vasya thinks that leaving open some expensive and some cheap roads at the same time is not a good idea beacuse it can increase social tension in the city. That's why he wants to minimize the price spread between the most expensive and the cheapest roads. Help Vasya choose the roads to keep open.

입력

The first line contains integers nn и mm --- the number of city districts and roads accordingly (2≤n≤30,000;n−1≤m≤30,0002 \leq n \leq 30\\,000; n - 1 \leq m \leq 30\\,000). The next mm lines contain triples of integers a_ia\_i, b_ib\_i и c_ic\_i, meaning that between the city districts a_ia\_i и b_ib\_i there is a road with the price c_ic\_i (1≤a_i,b_i≤n1 \leq a\_i, b\_i \leq n; a_i≠b_ia\_i \neq b\_i; 1≤c_i≤1091 \leq c\_i \leq 10^9). There can be several roads between two districts.

출력

In the only line output the sequence of integers --- 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.

예제2

  1. 예제 1

    입력
    3 3
    1 2 1
    2 3 3
    3 1 4
    
    예상 출력
    2 3
    
  2. 예제 2

    입력
    4 5
    1 2 1
    2 3 1
    1 3 2
    1 4 2
    2 4 1
    
    예상 출력
    1 2 5