CF1817B.Fish Graph

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a simple undirected graph with nn nodes and mm edges. Note that the graph is not necessarily connected. The nodes are labeled from 11 to nn .

We define a graph to be a Fish Graph if it contains a simple cycle with a special node uu belonging to the cycle. Apart from the edges in the cycle, the graph should have exactly 22 extra edges. Both edges should connect to node uu , but they should not be connected to any other node of the cycle.

Determine if the graph contains a subgraph that is a Fish Graph, and if so, find any such subgraph.

In this problem, we define a subgraph as a graph obtained by taking any subset of the edges of the original graph.

Visualization of example 1. The red edges form one possible subgraph that is a Fish Graph.

输入格式

The first line of input contains the integer tt ( 1t10001 \leq t \leq 1000 ), the number of test cases. The description of test cases follows.

The first line of each test case contains two integers, nn and mm ( 1n,m20001 \le n, m \le 2\,000 ) — the number of nodes and the number of edges.

Each of the next mm lines contains the description of an edge. Each line contains two integers uiu_i and viv_i ( 1ui,vin1 \leq u_i, v_i \leq n , uiviu_i\neq v_i ) — an edge connects node uiu_i to node viv_i .

It is guaranteed that no two edges connect the same unordered pair of nodes.

Furthermore, it is guaranteed that the sum of nn and the sum of mm over all test cases both do not exceed 20002\,000 .

输出格式

For each testcase, output "YES" if the graph contains a subgraph that is a Fish Graph, otherwise print "NO". If the answer is "YES", on the following lines output a description of the subgraph.

The first line of the description contains one integer kk — the number of edges of the subgraph.

On the next kk lines, output the edges of the chosen subgraph. Each of the kk lines should contains two integers uu and vv ( 1u,vn1\le u, v\le n , uvu\neq v ) — the edge between uu and vv belongs to the subgraph. The order in which uu and vv are printed does not matter, as long as the two nodes are connected by an edge in the original graph. The order in which you print the edges does not matter, as long as the resulting subgraph is a fish graph.

If there are multiple solutions, print any.

输入输出样例

  • 输入#1

    3
    7 8
    1 2
    2 3
    3 4
    4 1
    4 5
    4 6
    4 2
    6 7
    7 7
    6 7
    1 2
    2 3
    3 4
    4 1
    1 3
    3 5
    4 4
    1 3
    3 4
    4 1
    1 2

    输出#1

    YES
    6
    5 4
    6 4
    4 3
    1 4
    2 1
    3 2
    YES
    5
    5 3
    2 3
    3 1
    4 3
    1 4
    NO

说明/提示

In the first example, a possible valid subgraph contains the cycle 123411 \rightarrow 2 \rightarrow 3 \rightarrow 4 \rightarrow 1 . The special node of this cycle is node 44 . The two extra edges 454 - 5 and 464 - 6 are both connected to 44 , completing the Fish Graph.

In the second example, a possible valid subgraph contains the cycle 13411 \rightarrow 3 \rightarrow 4 \rightarrow 1 . The special node of this cycle is node 33 . The two extra edges 323 - 2 and 353 - 5 are both connected to 33 , completing the Fish Graph.

In the last example, it can be proven that there is no valid subgraph.

首页