Edges, Colors and MST

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

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 N1N-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 (2N21052 \le N \le 2 \cdot 10^5, N1M2105N-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 (1a_i,b_iN1 \le a\_i, b\_i \le N, 0c_i10 \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.