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

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

Bounded Spanning Tree

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

요약
주어진 그래프에서 처음 n-1개의 간선이 최소 신장 트리를 이루도록, 각 간선의 허용 구간을 지키며 1부터 m까지 서로 다른 가중치를 배정하는 문제이다.
난이도

보통10점 중 7점

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

문제

You are given a connected undirected edge-weighted graph with nn vertices and mm edges. There are no self-loops in this graph (that is, there is no edge which goes from a vertex to itself), but there can be multiple edges between some pairs of vertices.

Your friend told you the following about this graph:

  • The edge weights are distinct integers from the range \[1,m]\[1,m]. In other words, they form some permutation of integers from 11 to mm.
  • The weight of the ii-th edge is from the range \[l,r]\[l , r] for each ii from 11 to mm.
  • The edges with indices 1,2,…,n−11, 2, \dots ,n - 1 (the first n−1n - 1 edges in the input) form a minimum spanning tree of this graph.

You want to know if it is possible. Determine if there exist such assignments of edge weights for which these conditions hold and if yes, find any of them.

As a reminder, a spanning tree of a graph is any subset of its edges that forms a tree (connected graph on nn vertices with n−1n - 1 edges). The minimum spanning tree of a graph is any spanning tree with the smallest sum of weights among all spanning trees of the graph.

입력

The first line contains a single integer tt (1≤t≤1051 ≤ t ≤ 10^5) - the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and mm (1≤n−1≤m≤5⋅1051 ≤ n - 1 ≤ m ≤ 5 ⋅ 10^5) - the number of vertices and the number of edges, respectively.

The ii-th of the following mm lines contains four integers u_iu\_i, v_iv\_i, l_il\_i, r_ir\_i (1≤u<v≤n1 ≤ u < v ≤ n, 1≤l≤r≤m1 ≤ l ≤ r ≤ m) - indicating that there is an edge connecting vertices u_iu\_i, v_iv\_i, and that its weight should be in range \[l_i,r_i]\[l\_i, r\_i].

It's guaranteed that for each test case, edges with indices 1,2,…,n−11, 2, \dots , n - 1 form a spanning tree of the given graph.

It's guaranteed the sum of m over all test cases doesn't exceed 5⋅1055 ⋅ 10^5.

출력

For each test case, if an array of edge weights that satisfy the conditions doesn't exist, output "NO" in the first line.

Otherwise, in the first line, output "YES". In the second line output mm integers w_1,w_2,…,w_mw\_1 ,w\_2 , \dots ,w\_m (1≤w_i≤m1 ≤ w\_i ≤ m, all w_iw\_i are distinct) - the edge weights (where w_iw\_i is the weight assigned to the ii-th edge in the input).

If there are multiple answers, output any of them.

You can output each letter in any case (for example, "YES", "Yes", "yes", "yEs", "yEs" will be recognized as a positive answer).

예제1

  1. 예제 1

    입력
    3
    4 6
    1 2 1 3
    1 3 2 6
    3 4 1 2
    1 4 2 5
    2 3 2 4
    2 4 4 6
    4 4
    1 2 2 2
    2 3 3 3
    3 4 4 4
    1 4 1 4
    5 6
    1 2 1 1
    2 3 1 2
    3 4 2 4
    4 5 6 6
    1 4 4 6
    1 4 5 6
    
    예상 출력
    YES
    2 3 1 5 4 6
    NO
    YES
    1 2 3 6 4 5