CF730K.Roads Orientation Problem

普及/提高-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Berland consists of nn cities and mm bidirectional roads connecting pairs of cities. There is no road connecting a city to itself, and between any pair of cities there is no more than one road. It is possible to reach any city from any other moving along roads.

Currently Mr. President is in the city ss and his destination is the city tt . He plans to move along roads from ss to tt ( sts≠t ).

That's why Ministry of Fools and Roads has difficult days. The minister is afraid that Mr. President could get into a traffic jam or get lost. Who knows what else can happen!

To be sure that everything goes as planned, the minister decided to temporarily make all roads one-way. So each road will be oriented in one of two possible directions. The following conditions must be satisfied:

  • There should be no cycles along roads after orientation.
  • The city ss should be the only such city that all its roads are oriented out (i.e. there are no ingoing roads to the city ss and the city ss is the only such city).
  • The city tt should be the only such city that all its roads are oriented in (i.e. there are no outgoing roads from the city tt and the city tt is the only such city).

Help the minister solve his problem. Write a program to find any such orientation of all roads or report that no solution exists.

输入格式

Each test in this problem contains one or more test cases to solve. The first line of the input contains positive number TT — the number of cases to solve.

Each case starts with a line containing four integers nn , mm , ss and tt ( 2<=n<=41052<=n<=4·10^{5} , 1<=m<=1061<=m<=10^{6} , 1<=s,t<=n1<=s,t<=n , sts≠t ) — the number of cities, the number of roads and indices of departure and destination cities. The cities are numbered from 11 to nn .

The following mm lines contain roads, one road per line. Each road is given as two integer numbers xjx_{j} , yjy_{j} ( 1<=xj,yj<=n1<=x_{j},y_{j}<=n , xjyjx_{j}≠y_{j} ), which means that the jj -th road connects cities xjx_{j} and yjy_{j} . There is at most one road between any pair of cities. It is possible to reach any city from any other moving along roads.

The sum of values nn over all cases in a test doesn't exceed 41054·10^{5} . The sum of values mm over all cases in a test doesn't exceed 10610^{6} .

输出格式

For each case print "Yes" if the answer exists. In the following mm lines print roads in the required directions. You can print roads in arbitrary order. If there are multiple answers, print any of them.

Print the only line "No" if there is no answer for a case.

输入输出样例

  • 输入#1

    2
    4 4 1 2
    1 2
    2 3
    3 4
    4 1
    3 2 1 3
    3 1
    2 3
    

    输出#1

    Yes
    1 2
    3 2
    4 3
    1 4
    No
    
首页