#Q107. 「一本通 3.7 例 1」欧拉回路
「一本通 3.7 例 1」欧拉回路
Description
Original source: UOJ #117
One day, a soulful artist drew a graph. Now, you are asked to find an Eulerian circuit, i.e., a cycle in the graph where each edge appears exactly once.
There are two subtasks:
-
The graph is undirected. (50 points)
-
The graph is directed. (50 points)
Input Format
The first line contains an integer , representing the subtask number. , where indicates the undirected graph case, and indicates the directed graph case.
The second line contains two integers , representing the number of nodes and edges in the graph.
In the next lines, the -th line contains two integers , representing the -th edge (numbered starting from 1). It is guaranteed that .
-
If , it means there is an undirected edge between and .
-
If , it means there is a directed edge from to .
The graph may contain multiple edges and self-loops.
Output Format
If it is impossible to draw the graph in one stroke, output a single line NO.
Otherwise, output a line YES, followed by a line describing the solution.
-
If , output integers . Let , then represents the index of the -th edge traversed. If is positive, it means moving from to ; otherwise, it means moving from to .
-
If , output integers , where represents the index of the -th edge traversed.
Sample 1
1
3 3
1 2
2 3
1 3
YES
1 2 -3
Sample 2
2
5 6
2 3
2 5
3 4
1 2
4 2
5 1
YES
4 1 3 5 2 6
Data Range and Hints