Bounded Spanning Tree

Time limit: 2.5s Memory limit: 256MB Input: Output:

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 ithi^{th} edge is from the range [li,ri][l_i, r_i] for each ii from 11 to mm.
  • The edges with indices 1,2,,n11, 2,\dots, n − 1 (the first n1n − 1 edges in the input) form a minimum spanning tree of this graph.

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 n1n − 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.

Task

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.

Input data

The first line contains a single integer tt — the number of test cases. The description of test cases follows.

The first line of each test case contains two integers nn and mm — the number of vertices and the number of edges, respectively.
The ithi^{th} of the following mm lines contains four integers uiu_i, viv_i, lil_i, rir_i — indicating that there is an edge connecting vertices ui,viu_i, v_i, and that its weight should be in range [li,ri][l_i, r_i].

Output data

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 w1,w2,,wmw_1, w_2, \dots, w_m (1wim1 \leq w_i \leq m, all wiw_i are distinct) — the edge weights (where wiw_i is the weight assigned to the ithi^{th} edge in the input).

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

Constraints and clarifications

  • 1t101 \leq t \leq 10
  • 1n1m51051 \leq n − 1 \leq m ≤ 5 \cdot 10^5
  • 1ui<vin,  1lirim1 \leq u_i < v_i \leq n,\ \ 1 \leq l_i \leq r_i \leq m
  • It's guaranteed that for each test case, edges with indices 1,2,,n11, 2,\dots,n − 1 form a spanning tree of the given graph.
  • It's guaranteed the sum of mm over all test cases doesn't exceed 51055 \cdot 10^5.
  • If there are multiple answers, output any of them.
# Points Constraints
1 4 li=ril_i = r_i (1im1 \leq i \leq m)
2 6 The sum of mm over all test cases doesn't exceed 1010.
3 10 The sum of mm over all test cases doesn't exceed 2020.
4 10 m=n1m = n − 1, the sum of mm over all test cases doesn't exceed 500500.
5 7 m=n1m = n − 1
6 20 m=nm = n
7 11 The sum of mm over all test cases doesn't exceed 5 0005\ 000.
8 8 ui=iu_i = i, vi=i+1v_i = i + 1 (1in11 \leq i \leq n − 1)
9 12 The sum of mm over all test cases doesn't exceed 10510^5.
10 12 No additional constraints.

Example

stdin

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

stdout

YES
2 3 1 5 4 6
NO
YES
1 2 3 6 4 5

Log in or sign up to be able to send submissions!