아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Edges, Colors and MST

시간 제한2초메모리 제한1024 MB

요약
1부터 M까지의 순열을 간선 가중치로 부여해 최소 신장 트리가 주어진 빨간 신장 트리와 정확히 일치하도록 만들되, 수열을 사전순으로 가장 작게 만든다.
난이도

보통10점 중 7점

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

문제

There is an undirected simple connected graph GG with NN vertices and MM edges. The vertices of GG are numbered from 1 to NN, and the edges are numbered from 1 to MM. Edge ii connects vertices u_iu\_i and v_iv\_i.

Given is a sequence C=(c_1,c_2,…,c_M)C = (c\_1, c\_2, \ldots, c\_M) of length MM, consisting of 0s and 1s. Edge ii is painted blue when c_i=0c\_i=0, and is painted red when c_i=1c\_i=1. The edges are colored in such a way that there are exactly N−1N-1 red edges and they are forming a spanning tree of GG.

Find the lexicographically smallest permutation P=(p_1,p_2,…,p_M)P = (p\_1, p\_2, \ldots, p\_M) that satisfies the following condition: if, for each ii, the weight of edge ii is p_ip\_i, then all the edges used in the minimal spanning tree of GG are red.

Note that the minimal spanning tree of GG is uniquely determined under those conditions.

입력

The first line of input contains two integers NN and MM: the number of vertices and edges in graph GG, respectively (2≤N≤2⋅1052 \le N \le 2 \cdot 10^5, N−1≤M≤2⋅105N-1 \le M \le 2 \cdot 10^5).

The following MM lines contain descriptions of the edges. Each description contains three integers a_ia\_i, b_ib\_i and c_ic\_i (1≤a_i,b_i≤N1 \le a\_i, b\_i \le N, 0≤c_i≤10 \le c\_i \le 1): the vertices that are connected by this edge and the color of the edge (red if c_i=1c\_i=1 and blue otherwise).

You may assume that there are no multiple edges nor loops, that the given graph is connected, and that the red edges are forming a spanning tree of the given graph.

출력

Print MM integers that form the lexicographically smallest permutation PP that satisfies the following condition: if, for each ii, the weight of edge ii is p_ip\_i, then all the edges used in the minimal spanning tree of GG are red.

예제1

  1. 예제 1

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