Problem
Given: A positive integer and simple directed graphs with at most vertices and edges each in the edge list format.
Return: For each graph, output a vertex from which all other vertices are reachable (if such a vertex exists) and "-1" otherwise.
Source: Algorithms by Dasgupta, Papadimitriou, Vazirani. McGraw-Hill. 2006.
给定:正整数 和 简单的有向图 ,最多 顶点和 以边缘列表格式边缘化。
返回值:对于每个图,输出一个顶点,从该顶点可以到达所有其他顶点(如果存在这样的顶点),否则返回“ -1”。
资料来源:Dasgupta,Papadimitriou,Vazirani的算法。麦格劳-希尔。2006年
Sample Dataset
2 3 2 3 2 2 1 3 2 3 2 1 2
Sample Output
3 -1