Logo
(追記) (追記ここまで)

27461번 - Bounded Spanning Tree 서브태스크스페셜 저지다국어

시간 제한메모리 제한제출정답맞힌 사람정답 비율
2.5 초 1024 MB101181617.978%

문제

You are given a connected undirected edge-weighted graph with $n$ vertices and $m$ 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]$. In other words, they form some permutation of integers from 1ドル$ to $m$.
  • The weight of the $i$-th edge is from the range $[l , r]$ for each $i$ from 1ドル$ to $m$.
  • The edges with indices 1,ドル 2, \dots ,n - 1$ (the first $n - 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 $n$ vertices with $n - 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 $t$ (1ドル ≤ t ≤ 10^5$) - the number of test cases. The description of test cases follows.

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

The $i$-th of the following $m$ lines contains four integers $u_i,ドル $v_i,ドル $l_i,ドル $r_i$ (1ドル ≤ u < v ≤ n,ドル 1ドル ≤ l ≤ r ≤ m$) - indicating that there is an edge connecting vertices $u_i,ドル $v_i,ドル and that its weight should be in range $[l_i, r_i]$.

It's guaranteed that for each test case, edges with indices 1,ドル 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ドル ⋅ 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 $m$ integers $w_1 ,w_2 , \dots ,w_m$ (1ドル ≤ w_i ≤ m,ドル all $w_i$ are distinct) - the edge weights (where $w_i$ is the weight assigned to the $i$-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).

제한

서브태스크

번호배점제한
14

$l_i = r_i$ (1ドル ≤ i ≤ m$)

26

The sum of $m$ over all test cases doesn't exceed 10ドル$

310

The sum of $m$ over all test cases doesn't exceed 20ドル$

410

$m = n - 1,ドル the sum of $m$ over all test cases doesn't exceed 500ドル$

57

$m = n - 1$

620

$m = n$

711

The sum of $m$ over all test cases doesn't exceed 5000ドル$

88

$u_i = i,ドル $v_i = i + 1$ (1ドル ≤ i ≤ n - 1$)

912

The sum of $m$ over all test cases doesn't exceed 10ドル^5$

1012

No additional constraints

예제 입력 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

예제 출력 1

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

힌트

출처

Olympiad > European Junior Olympiad in Informatics > eJOI 2022 3번

채점 및 기타 정보

  • 예제는 채점하지 않는다.
  • 이 문제의 채점 우선 순위는 2이다.
(追記) (追記ここまで)

출처

대학교 대회

  • 사업자 등록 번호: 541-88-00682
  • 대표자명: 최백준
  • 주소: 서울시 서초구 서초대로74길 29 서초파라곤 412호
  • 전화번호: 02-521-0487 (이메일로 연락 주세요)
  • 이메일: contacts@startlink.io
  • 통신판매신고번호: 제 2017-서울서초-2193 호

AltStyle によって変換されたページ (->オリジナル) /