#P11093. [ROI 2021] 树制游戏 (Day 2)

[ROI 2021] 树制游戏 (Day 2)

Problem Description

Translated from ROI 2021 D2T2

Vasya recently came up with a new kind of entertainment. He wants a directed connected graph with nn vertices and 2×(n1)2\times(n−1) edges to be his toy. This graph satisfies the following condition: for every edge (u,v)(u, v) in the graph, there is also a reverse edge (v,u)(v, u). In other words, this graph is obtained from a tree, where each undirected edge is replaced by two directed edges in opposite directions.

Vasya calls such a pair of edges (e1,e2)(e_1, e_2) a “gadget” if the endpoint of e1e_1 is the start point of e2e_2, or the endpoint of e2e_2 is the start point of e1e_1 (in particular, two opposite directed edges also form a “gadget”). Simply put, a “gadget” is a path of length 22. Vasya’s entertainment is to partition all edges of the graph into pairwise disjoint “gadgets”. Of course, for the original graph, this is easy to do.

However, Vasya’s good friend Petya removed 2k2k directed edges from the tree, so that the remaining graph has m=2×(n1)2×km = 2\times (n - 1) - 2\times k directed edges.

Now Vasya wants to know whether it is possible to partition the remaining edges into pairwise disjoint “gadgets”. If it is possible, he also wants to find one such partition.

Input Format

The first line contains two integers nn and mm, representing the number of vertices and the number of remaining edges. It is guaranteed that mm is even.

The next mm lines each contain two integers uiu_i and viv_i, indicating a remaining directed edge from uiu_i to viv_i.

Output Format

If it is impossible to partition the edges into “gadgets”, output No.

Otherwise, output Yes, and then output m2\frac{m}{2} lines. Each line contains 44 numbers, describing the two directed edges in one “gadget”. Each directed edge is described by its start point and endpoint.

5 6
1 2
2 1
1 5
2 3
2 4
4 2
Yes
1 2 2 3
2 1 1 5
2 4 4 2
4 4
2 1
2 3
2 4
4 2
No
4 4
1 2
2 1
3 4
4 3
Yes
1 2 2 1
3 4 4 3

Hint

The “gadget” partition for the first sample is shown in the figure below. Two lines of the same type form one “gadget”.

For 100%100\% of the testdata, $2 \le n \le 150000,2 \le m \le 2\times n - 2,1 \le u_i, v_i \le n$.

Subtask Score nn\le Special property of mm
11 77 1010 m20m\le20
22 1010 200200 None
33 1111 30003000 m=2×n4m=2\times n-4
44 2929 None
55 1111 150000150000 m=2×n4m=2\times n-4
66 3232 None

Translated by ChatGPT 5