#P13783. [eJOI 2022] Bounded Spanning Tree
[eJOI 2022] Bounded Spanning Tree
题目描述
You are given a connected undirected edge-weighted graph with vertices and 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 . In other words, they form some permutation of integers from 1 to .
- The weight of the -th edge is from the range for each from 1 to .
- The edges with indices (the first 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 vertices with 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 () - the number of test cases. The description of test cases follows.
The first line of each test case contains two integers and () - the number of vertices and the number of edges, respectively.
The -th of the following lines contains four integers (, ) - indicating that there is an edge connecting vertices , and that its weight should be in range .
It's guaranteed that for each test case, edges with indices form a spanning tree of the given graph.
It's guaranteed the sum of over all test cases doesn't exceed .
输出格式
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 integers (, all are distinct) - the edge weights (where is the weight assigned to the -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).
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
提示
Scoring
- (4 points): ()
- (6 points): The sum of over all test cases doesn't exceed 10
- (10 points): The sum of over all test cases doesn't exceed 20
- (10 points): , the sum of over all test cases doesn't exceed 500
- (7 points):
- (20 points):
- (11 points): The sum of over all test cases doesn't exceed 5000
- (8 points): ()
- (12 points): The sum of over all test cases doesn't exceed
- (12 points): No additional constraints