New Megacity
InterviewTime limit2.5sMemory limit2048 MB
Given n cities and m weighted roads, label each road 1 if every minimum spanning tree uses it, 2 if some do but not all, and 3 if none do.
- Level
Medium6 of 10
- Topics
- Minimum spanning tree, Union-find, Graph, Sorting
- Solved
- No attempts yet
Problem
You are part of a large project to design a new megacity that connects cities. There are candidate roads, and each road has a construction cost. All cities must be connected at the minimum total cost, which means they must form a minimum spanning tree (MST). Not all roads matter equally, though. Classify each road into one of three types:
- Type 1: The road is included in every MST.
- Type 2: The road is included in at least one MST, but not in every MST.
- Type 3: The road is not used in any MST.
Input
The first line contains two integers and , the number of cities and the number of candidate roads. The bounds are and . Each of the next lines contains three integers , , and , meaning that a road connects cities and and costs . Here , , and . No two cities are connected by more than one road. The input always has at least one MST.
Output
Print lines. The -th line contains a single integer, 1, 2, or 3, which is the type of the -th road in input order.