Urban geography
InterviewTime limit2sMemory limit1024 MB
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 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 and : the number of city districts and roads, respectively (; ). The next lines contain triples of integers , , and , meaning that between the city districts and there is a road with the price (; ; ). 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.