Rigged Roads
Time limit2sMemory limit512 MB
Given a connected graph and a spanning tree R, assign distinct weights 1 to E so that R is the unique MST, with the weight list lexicographically smallest.
- Level
Medium7 of 10
- Topics
- Graph, Minimum spanning tree, Union-find, Greedy
- Solved
- No attempts yet
Problem
Silvermill is on a tight budget lately, and Peanut, its mayor, plans to demolish some roads to save on maintenance costs. Silvermill has road intersections and roads running between them. The -th road connects intersections and . Intersections are labelled and roads are labelled . Any two intersections can reach each other directly or indirectly, and no two roads share the same endpoints.
Peanut has hired you to assess the maintenance cost of the roads. Your task is to report a list where is a permutation of and is the cost to keep road .
Peanut then keeps a subset of roads such that all intersections remain connected and the total cost of the kept roads is minimal. In other words, Peanut keeps the minimum spanning tree under the weights you choose. The costs are distinct, so the minimum spanning tree is unique.
You have a hidden agenda. You want Peanut to keep a set of roads that forms a spanning tree, and you can make that happen by choosing carefully. Find the lexicographically smallest permutation for which the minimum spanning tree of the city is .
is smaller than if there is a with such that and for all .
Input
Read from standard input. The first line contains two integers and . The next lines contain the two integers and describing road . The last line contains integers, the labels of the roads in .
Output
Print to standard output. Print integers on a single line, the lexicographically smallest permutation that makes the minimum spanning tree.
Constraints
It is possible to travel between any two road intersections using only roads in .