CodeTON Round 1 (Div. 1 + Div. 2, Rated, Prizes!)
I
Neighbour Ordering
Codeforces
3500
原题
← H→
翻译中…

Given an undirected graph $G$, we say that a neighbour ordering is an ordered list of all the neighbours of a vertex for each of the vertices of $G$. Consider a given neighbour ordering of $G$ and three vertices $u$, $v$ and $w$, such that $v$ is a neighbor of $u$ and $w$. We write $u \lt _{v} w$ if $u$ comes after $w$ in $v$'s neighbor list.

翻译中…

A neighbour ordering is said to be good if, for each simple cycle $v_1, v_2, \ldots, v_c$ of the graph, one of the following is satisfied:

翻译中…
  • $v_1 \lt _{v_2} v_3, v_2 \lt _{v_3} v_4, \ldots, v_{c-2} \lt _{v_{c-1}} v_c, v_{c-1} \lt _{v_c} v_1, v_c \lt _{v_1} v_2$.
  • $v_1 \gt _{v_2} v_3, v_2 \gt _{v_3} v_4, \ldots, v_{c-2} \gt _{v_{c-1}} v_c, v_{c-1} \gt _{v_c} v_1, v_c \gt _{v_1} v_2$.
翻译中…

Given a graph $G$, determine whether there exists a good neighbour ordering for it and construct one if it does.

翻译中…

Input

翻译中…

The input consists of multiple test cases. The first line contains a single integer $t$ ($1 \leq t \leq 10^4$) — the number of test cases. Description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$ and $m$ ($2 \leq n \leq 3 \cdot 10^5$, $1 \leq m \leq 3 \cdot 10^5$), the number of vertices and the number of edges of the graph.

翻译中…

The next $m$ lines each contain two integers $u, v$ ($0 \leq u, v \lt n$), denoting that there is an edge connecting vertices $u$ and $v$. It is guaranteed that the graph is connected and there are no loops or multiple edges between the same vertices.

翻译中…

The sum of $n$ and the sum of $m$ for all test cases are at most $3 \cdot 10^5$.

翻译中…

Output

翻译中…

For each test case, output one line with YES if there is a good neighbour ordering, otherwise output one line with NO. You can print each letter in any case (upper or lower).

翻译中…

If the answer is YES, additionally output $n$ lines describing a good neighbour ordering. In the $i$-th line, output the neighbours of vertex $i$ in order.

翻译中…

If there are multiple good neigbour orderings, print any.

翻译中…

样例

Input #1
3
5 6
0 1
0 2
1 2
2 3
3 4
4 1
2 1
0 1
6 10
0 1
2 0
0 3
0 4
1 2
1 4
2 3
2 5
3 5
4 5
Output #1
YES
1 2
4 2 0
0 1 3
2 4
3 1
YES
1
0
NO
InputCopy OutputCopy
题目信息
题号
1656I
时间限制
5 s
内存限制
256 MB
标签
构造
图论

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。