Problem
Given: A positive integer and simple directed graphs with positive integer edge weights and at most vertices in the edge list format.
Return: For each graph, output the length of a shortest cycle going through the first specified edge if there is a cycle and "-1" otherwise.
给定:正整数 和 简单有向图具有正整数的边权重,并且至多边列表格式的顶点。
返回值:对于每个图形,如果存在循环,则输出经过第一个指定边的最短循环的长度,否则输出“ -1”。
Sample Dataset
2
4 5
2 4 2
3 2 1
1 4 3
2 1 10
1 3 4
4 5
3 2 1
2 4 2
4 1 3
2 1 10
1 3 4
Sample Output
-1 10