Equivalent Pipelines

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

문제

You are planning to construct a water pipeline network, connecting nn buildings in KAIST. Due to budget problems, you can only use n1n-1 pipes. Each pipe is undirected and connects two different buildings, and all nn buildings must be pairwise connected through some sequence of pipes. These pipes form a network.

As a careful planner, you designed dd different networks and want to compare them. One can describe each pipe in the network with a durability, which is a single positive integer. Given a network TT, define the vulnerability v_T(i,j)v\_{T}(i, j) of two distinct buildings ii and jj to be the minimum durability of a pipe whose removal separates buildings ii and jj. In other words, v_T(i,j)v\_{T}(i, j) is the minimum durability over all pipes on the path connecting ii to jj.

If two networks T_1T\_{1} and T_2T\_{2} satisfy v_T_1(i,j)=v_T_2(i,j)v\_{T\_1}(i, j) = v\_{T\_2}(i, j) for all 1i<jn1 \le i < j \le n, we say T_1T\_{1} and T_2T\_{2} are equivalent. To filter out unnecessary plans, group the dd designs up to equivalency.

입력

The first line contains two integers dd and nn (d1d \ge 1, n2n \ge 2, dn500,000d\cdot n \le 500\\,000), separated by a space.

From the second line, the descriptions for the dd designs are given. Each design is described over n1n-1 lines, each line consisting of three integers aa, bb and cc (1a,bn1 \le a, b \le n, aba \neq b, 1c1091 \le c \le 10^{9}), indicating there is a pipe connecting buildings aa and bb directly, whose durability is equal to cc.

출력

Output dd integers in a line. For 1id1 \le i \le d, the ii-th number should be the minimum index jj, where the jj-th network in the input is equivalent to the ii-th network in the input.