| 시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
|---|---|---|---|---|---|
| 2.5 초 | 2048 MB | 135 | 50 | 44 | 40.367% |
You are involved in a huge project to design a new megacity connecting $n$ cities using a given set of $m$ potential roads, each with an associated cost. All cities should be connected with the minimum total cost, that is, they form a Minimum Spanning Tree (MST). However, not all roads are equally important. Your job is to determine the importance of each road on the following categories:
Given a road network of $n$ cities with $m$ roads with associated costs, write a program to output the type of each road.
Your program is to read from standard input. The input starts with a line containing two integers $n$ and $m,ドル where $n$ is the number of cities (2ドル ≤ n ≤ 100,000円$) and $m$ is the number of potential roads ($n - 1 ≤ m≤\min(100,000,円 n(n - 1)/2)$).
In the following $m$ lines, the $i$-th road is given by three integers $x,ドル $y,ドル $z$ where $x$ and $y$ are the cities connected by the road (1ドル ≤ x, y ≤ n,ドル $x \ne y$), and $z$ is the cost of building that road (1ドル ≤ z ≤ 100,000円$). Each pair of cities is connected by at most one road, that is, there are no multiple edges between the same pair of cities.
It is guaranteed that at least one MST always exists for the given input.
Your program is to write to standard output. Print $m$ lines. The $i$-th line should contain a single integer representing the type of the $i$-th road (1, 2, or 3), in the same order as the input.
4 6 1 2 3 1 4 4 2 4 6 2 3 2 4 3 5 3 1 3
2 1 3 1 3 2
4 5 1 2 1 1 3 1 2 3 1 2 4 1 3 4 1
2 2 2 2 2