AQT is studying directed graphs and has encountered the following problem: given a directed graph consisting of -1
if none exists)?
Constraints
Subtask 1 [5%]
Subtask 2 [10%]
If a directed edge connecting node
Subtask 3 [15%]
The graph will have no cycles.
Subtask 4 [70%]
No additional constraints.
Input Specification
The first line will contain the integers
The next
Output Specification
Output a pair
If no answer exists, output -1
instead.
Sample Input 1
5 5
1 4
2 5
3 1
2 4
1 2
Sample Output 1
3 5
Explanation 1
Here is the graph given in the input:
The pairs of vertices
The output is thus 3 5
as
This graph also satisfies subtask 3.
Sample Input 2
5 5
4 3
5 2
3 1
4 2
5 1
Sample Output 2
-1
Explanation 2
Here is the graph given in the input:
There are no pairs of vertices -1
.
This graph also satisfies subtask 3.
Sample Input 3
4 6
3 1
1 2
3 2
2 1
2 3
1 3
Sample Output 3
2 3
Explanation 3
Here is the graph given in the input:
This graph satisfies subtask 2.
Sample Input 4
6 6
6 4
4 1
6 1
3 2
2 5
3 5
Sample Output 4
3 5
Explanation 4
Here is the graph given in the input:
This graph satisfies subtask 3.
Comments