New Megacity

시간 제한2.5초메모리 제한2048 MB

요약
가중 그래프의 각 간선을 모든 최소 신장 트리에 포함되는지, 일부에만 포함되는지, 어디에도 포함되지 않는지 분류한다.
난이도

어려움10점 중 8점

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

문제

You are involved in a huge project to design a new megacity connecting nn cities using a given set of mm 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:

  • Type 1: The road is included in every possible MST that connects all cities. This means that this road is essential for the optimal solution.
  • Type 2: The road appears in at least one MST but does not in all.
  • Type 3: The road is never used in any MST; it does not contribute to the least costly connection of all cities.

Given a road network of nn cities with mm 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 nn and mm, where nn is the number of cities (2≤n≤100,0002 ≤ n ≤ 100\\,000) and mm is the number of potential roads (n−1≤m≤min⁡(100,000,n(n−1)/2)n - 1 ≤ m≤\min(100\\,000, n(n - 1)/2)).

In the following mm lines, the ii-th road is given by three integers xx, yy, zz where xx and yy are the cities connected by the road (1≤x,y≤n1 ≤ x, y ≤ n, x≠yx \ne y), and zz is the cost of building that road (1≤z≤100,0001 ≤ 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 mm lines. The ii-th line should contain a single integer representing the type of the ii-th road (1, 2, or 3), in the same order as the input.

예제2

  1. 예제 1

    입력
    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
    
  2. 예제 2

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