#P14883. [ICPC 2019 Yokohama R] One-Way Conveyors

[ICPC 2019 Yokohama R] One-Way Conveyors

题目描述

You are working at a factory manufacturing many different products. Products have to be processed on a number of different machine tools. Machine shops with these machines are connected with conveyor lines to exchange unfinished products. Each unfinished product is transferred from a machine shop to another through one or more of these conveyors.

As the orders of the processes required are not the same for different types of products, the conveyor lines are currently operated in two-way. This may induce inefficiency as conveyors have to be completely emptied before switching their directions. Kaizen (efficiency improvements) may be found here!

Adding more conveyors is too costly. If all the required transfers are possible with currently installed conveyors operating in fixed directions, no additional costs are required. All the required transfers, from which machine shop to which, are listed at hand. You want to know whether all the required transfers can be enabled with all the conveyors operated in one-way, and if yes, directions of the conveyor lines enabling it.

输入格式

The input consists of a single test case of the following format.

$$\begin{aligned} &n \ m \\ &x_1 \ y_1 \\ &\vdots \\ &x_m \ y_m \\ &k \\ &a_1 \ b_1 \\ &\vdots \\ &a_k \ b_k \end{aligned}$$

The first line contains two integers nn (2n100002 \le n \le 10000) and mm (1m1000001 \le m \le 100000), the number of machine shops and the number of conveyors, respectively. Machine shops are numbered 1 through nn. Each of the following mm lines contains two integers xix_i and yiy_i (1xi<yin1 \le x_i < y_i \le n), meaning that the ii-th conveyor connects machine shops xix_i and yiy_i. At most one conveyor is installed between any two machine shops. It is guaranteed that any two machine shops are connected through one or more conveyors. The next line contains an integer kk (1k1000001 \le k \le 100000), which indicates the number of required transfers from a machine shop to another. Each of the following kk lines contains two integers aia_i and bib_i (1ain1 \le a_i \le n, 1bin1 \le b_i \le n, aibia_i \ne b_i), meaning that transfer from the machine shop aia_i to the machine shop bib_i is required. Either aiaja_i \ne a_j or bibjb_i \ne b_j holds for iji \ne j.

输出格式

Output “No” if it is impossible to enable all the required transfers when all the conveyors are operated in one-way. Otherwise, output “Yes” in a line first, followed by mm lines each of which describes the directions of the conveyors. All the required transfers should be possible with the conveyor lines operated in these directions. Each direction should be described as a pair of the machine shop numbers separated by a space, with the start shop number on the left and the end shop number on the right. The order of these mm lines do not matter as far as all the conveyors are specified without duplicates or omissions. If there are multiple feasible direction assignments, whichever is fine.

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