Problem
A directed graph is semi-connected if for all pairs of vertices there is either a path from to or a path from to .
Given: A positive integer and simple directed graphs with at most vertices each in the edge list format.
Return: For each graph, output "1" if the graph is semi-connected and "-1" otherwise.
如果对于所有成对的顶点,则有向图是半连接的 有一条路从 至 或从 至 。
返回值:对于每个图形,如果图形是半连接的,则输出“ 1”,否则为“ -1”。
Sample Dataset
2
3 2
3 2
2 1
3 2
3 2
1 2
Sample Output
1 -1