#abc142f. [abc142_f]Pure
[abc142_f]Pure
Problem Statement
Given is a directed graph with vertices and edges.
The vertices are numbered to , and the -th edge is directed from Vertex to Vertex .
It is guaranteed that the graph contains no self-loops or multiple edges.
Determine whether there exists an induced subgraph (see Notes) of such that the in-degree and out-degree of every vertex are both . If the answer is yes, show one such subgraph.
Here the null graph is not considered as a subgraph.
Notes
For a directed graph , we call a directed graph satisfying the following conditions an induced subgraph of :
- is a (non-empty) subset of .
- is the set of all the edges in that have both endpoints in .
Constraints
- All pairs are distinct.
- All values in input are integers.
Input
Input is given from Standard Input in the following format:
Output
If there is no induced subgraph of that satisfies the condition, print -1
. Otherwise, print an induced subgraph of that satisfies the condition, in the following format:
:
This represents the induced subgraph of with vertices whose vertex set is . (The order of does not matter.) If there are multiple subgraphs of that satisfy the condition, printing any of them is accepted.
Sample Input 1
4 5
1 2
2 3
2 4
4 1
4 3
Sample Output 1
3
1
2
4
The induced subgraph of whose vertex set is has the edge set . The in-degree and out-degree of every vertex in this graph are both .
Sample Input 2
4 5
1 2
2 3
2 4
1 4
4 3
Sample Output 2
-1
There is no induced subgraph of that satisfies the condition.
Sample Input 3
6 9
1 2
2 3
3 4
4 5
5 6
5 1
5 2
6 1
6 2
Sample Output 3
4
2
3
4
5