Edges, Colors and MST
시간 제한2초메모리 제한1024 MB
1부터 M까지의 순열을 간선 가중치로 부여해 최소 신장 트리가 주어진 빨간 신장 트리와 정확히 일치하도록 만들되, 수열을 사전순으로 가장 작게 만든다.
문제
There is an undirected simple connected graph with vertices and edges. The vertices of are numbered from 1 to , and the edges are numbered from 1 to . Edge connects vertices and .
Given is a sequence of length , consisting of 0s and 1s. Edge is painted blue when , and is painted red when . The edges are colored in such a way that there are exactly red edges and they are forming a spanning tree of .
Find the lexicographically smallest permutation that satisfies the following condition: if, for each , the weight of edge is , then all the edges used in the minimal spanning tree of are red.
Note that the minimal spanning tree of is uniquely determined under those conditions.
입력
The first line of input contains two integers and : the number of vertices and edges in graph , respectively (, ).
The following lines contain descriptions of the edges. Each description contains three integers , and (, ): the vertices that are connected by this edge and the color of the edge (red if 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 integers that form the lexicographically smallest permutation that satisfies the following condition: if, for each , the weight of edge is , then all the edges used in the minimal spanning tree of are red.