CF687A.NP-Hard Problem

普及/提高-

通过率:0%

AC君温馨提醒

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

题目描述

Recently, Pari and Arya did some research about NP-Hard problems and they found the minimum vertex cover problem very interesting.

Suppose the graph GG is given. Subset AA of its vertices is called a vertex cover of this graph, if for each edge uvuv there is at least one endpoint of it in this set, i.e. or (or both).

Pari and Arya have won a great undirected graph as an award in a team contest. Now they have to split it in two parts, but both of them want their parts of the graph to be a vertex cover.

They have agreed to give you their graph and you need to find two disjoint subsets of its vertices AA and BB , such that both AA and BB are vertex cover or claim it's impossible. Each vertex should be given to no more than one of the friends (or you can even keep it for yourself).

输入格式

The first line of the input contains two integers nn and mm ( 2<=n<=1000002<=n<=100000 , 1<=m<=1000001<=m<=100000 ) — the number of vertices and the number of edges in the prize graph, respectively.

Each of the next mm lines contains a pair of integers uiu_{i} and viv_{i} ( 1<=ui,vi<=n1<=u_{i},v_{i}<=n ), denoting an undirected edge between uiu_{i} and viv_{i} . It's guaranteed the graph won't contain any self-loops or multiple edges.

输出格式

If it's impossible to split the graph between Pari and Arya as they expect, print "-1" (without quotes).

If there are two disjoint sets of vertices, such that both sets are vertex cover, print their descriptions. Each description must contain two lines. The first line contains a single integer kk denoting the number of vertices in that vertex cover, and the second line contains kk integers — the indices of vertices. Note that because of m>=1m>=1 , vertex cover cannot be empty.

输入输出样例

  • 输入#1

    4 2
    1 2
    2 3
    

    输出#1

    1
    2 
    2
    1 3 
    
  • 输入#2

    3 3
    1 2
    2 3
    1 3
    

    输出#2

    -1
    

说明/提示

In the first sample, you can give the vertex number 22 to Arya and vertices numbered 11 and 33 to Pari and keep vertex number 44 for yourself (or give it someone, if you wish).

In the second sample, there is no way to satisfy both Pari and Arya.

首页