CF1835F.Good Graph

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

You are given a bipartite graph GG with the vertex set in the left part LL , in the right part RR , and mm edges connecting these two sets. We know that L=R=n|L| = |R| = n .

For any subset SLS \subseteq L , let N(S)N(S) denote the set of all neighbors of vertices in SS . We say that a subset SLS \subseteq L in graph GG is tight if S=N(S)|S| = |N(S)| . We say that graph GG is good if SL,SN(S)\forall_{S \subseteq L}, |S| \leq |N(S)| .

Your task is to verify whether the graph is good and, if so, to optimize it. If the graph is not good, find a subset SLS \subseteq L such that S>N(S)|S| > |N(S)| . However, if the graph is good, your task is to find a good bipartite graph GG' with the same set of vertices LRL \cup R , in which SL\forall_{S \subseteq L} , SS is tight in GG if and only if SS is tight in GG' . If there are multiple such graphs, choose one with the smallest possible number of edges. If there are still multiple such graphs, print any.

输入格式

The first line of the input contains two integers nn and mm ( 1n1031 \leq n \leq 10^3 , 0mn20 \leq m \leq n^2 ), separated by a single space. The number nn denotes the number of vertices in each of the sets LL and RR , and the number mm denotes the number of edges between them.

The following mm lines describe the edges. Each of them contains two integers ll and rr ( 1ln1 \leq l \leq n , n+1r2nn+1 \leq r \leq 2 \cdot n ), separated by a single space, indicating that there is an edge from vertex lLl \in L to vertex rRr \in R .

输出格式

If the graph GG given in the input is not good, output one word "NO" in the first line of the output. In the second line of the output, output the number kk , and in the third line, output kk numbers l1,l2,,lkl_1, l_2, \dots, l_k , separated by single spaces. These numbers should indicate that for the set S={l1,l2,,lk}S = \{l_1, l_2, \dots, l_k\} , S>N(S)|S| > |N(S)| .

However, if the graph GG given in the input is good, output one word "YES" in the first line of the output. In the second line of the output, output the number mm' , indicating the number of edges in the new, also good graph GG' . Then, in the following mm' lines, output the edges of the graph GG' in the same format as given in the input.

输入输出样例

  • 输入#1

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

    输出#1

    YES
    6
    1 4
    1 5
    2 5
    2 6
    3 6
    3 4
  • 输入#2

    3 4
    1 4
    1 5
    2 6
    3 6

    输出#2

    NO
    2
    2 3

说明/提示

In the first sample test, the graph GG is good; thus, we are looking for an equivalent graph with the same tight sets. The only tight set is {1,2,3}\{ 1, 2, 3 \} , which remains tight in the resulting graph. Moreover, no other set is tight in the resulting graph. One can prove that no graph with less than 66 edges and the same tight sets exists.

In the second sample test, the graph GG is not good. Set {2,3}\{ 2, 3 \} has only one neighbour — vertex 66 . Thus, {2,3}>{6}|\{ 2, 3 \}| > |\{ 6 \}| , which is a prove that the input graph is not good.

首页