#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:

  1. The graph is undirected. (50 points)

  2. The graph is directed. (50 points)

Input Format

The first line contains an integer tt, representing the subtask number. t{1,2}t \in \{1, 2\}, where t=1t = 1 indicates the undirected graph case, and t=2t = 2 indicates the directed graph case.

The second line contains two integers n,mn, m, representing the number of nodes and edges in the graph.

In the next mm lines, the ii-th line contains two integers vi,uiv_i, u_i, representing the ii-th edge (numbered starting from 1). It is guaranteed that 1vi,uin1 \leq v_i, u_i \leq n.

  1. If t=1t = 1, it means there is an undirected edge between viv_i and uiu_i.

  2. If t=2t = 2, it means there is a directed edge from viv_i to uiu_i.

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.

  1. If t=1t = 1, output mm integers p1,p2,,pmp_1, p_2, \dots, p_m. Let e=pie = \lvert p_i \rvert, then ee represents the index of the ii-th edge traversed. If pip_i is positive, it means moving from vev_e to ueu_e; otherwise, it means moving from ueu_e to vev_e.

  2. If t=2t = 2, output mm integers p1,p2,,pmp_1, p_2, \dots, p_m, where pip_i represents the index of the ii-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

1n105,0m2×1051 \leq n \leq 10^5, 0 \leq m \leq 2 \times 10^5