#P10179. 水影若深蓝

    ID: 11501 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 6 上传者: 标签>洛谷原创Special JudgeO2优化洛谷月赛

水影若深蓝

Background

Fanfan loves Arknights, and loves Mizuki and the Deepblue Tree even more. In the Year of the Dragon, he wants to build a Deepblue Tree that belongs only to him.

Problem Description

In a dream, in the hazy water shadows, Fanfan saw this Deepblue Tree that belongs only to him.

When the dream fell silent, he forgot everything, and only remembered that the tree has nn nodes.

Really? It seems not. There are mm things he still remembers clearly. The ii-th thing is: the unique simple path (not repeating any node) between nodes uiu_i and viv_i on this Deepblue Tree has exactly two edges.

Can you help Fanfan recall what this Deepblue Tree looks like? If there are multiple possibilities, you only need to output any one of them.

Of course, Fanfan can also wear out. Therefore, if you find that no matter what you do you cannot find a Deepblue Tree satisfying these mm things, you need to report that there is no solution.

Input Format

This problem has multiple test cases.

The first line contains a positive integer TT, the number of test cases.

For each test case:

The first line contains two non-negative integers n,mn,m, representing the number of nodes in the tree and the number of events in Fanfan's memory.

The next mm lines each contain two positive integers ui,viu_i,v_i, representing an event.

Output Format

For each test case:

  • If there is no tree that satisfies the conditions, output No.
  • Otherwise, output Yes on the first line, then output n1n-1 lines, each with a pair of positive integers (u,v)(u,v), representing the n1n-1 edges of the tree you give.

This problem uses a special judge, meaning that if there are multiple valid answers, you may output any one.

2
4 2
1 2
3 4
3 3
1 2
2 3
3 1
Yes
1 3
2 4
2 3
No

Hint

Sample 11 Explanation

For the first test case, it is not hard to verify that the given tree satisfies the conditions.

For the second test case, it can be proved that no tree satisfies the conditions.

Constraints

For 100%100\% of the data, 1T1051\le T\le 10^5, n2n\ge 2, m0m\ge 0, 1n3×1051\le \sum n\le 3\times 10^5, 0m3×1050\le \sum m\le 3\times 10^5, 1ui,vin1\le u_i,v_i\le n, uiviu_i\neq v_i.

This problem uses bundled testdata.

Subtask ID Special Constraints Score
Subtask #1 n,m9\sum n,\sum m\le 9 1010
Subtask #2 n,m50\sum n,\sum m\le 50
Subtask #3 n,m5000\sum n,\sum m\le 5000
Subtask #4 vi=ui+1v_i=u_i+1
Subtask #5 ui=1u_i=1
Subtask #6 ui1,vi1u_i\neq 1,v_i\neq 1
Subtask #7 T=1T=1
Subtask #8 None 3030

Translated by ChatGPT 5