Problem
The task is to use Bellman-Ford algorithm to check whether a given graph contains a cycle of negative weight.
Given: A positive integer and simple directed graphs with integer edge weights from to and vertices in the edge list format.
Return: For each graph, output "1" if it contains a negative weight cycle and "-1" otherwise.
任务是使用Bellman-Ford算法检查给定图是否包含负权重的循环。
给定:正整数 和 具有以下整数的权重的简单有向图 至 和 边列表格式的顶点。
返回值:对于每个图形,如果其包含负的重量循环,则输出“ 1”,否则输出“ -1”。
Sample Dataset
2 4 5 1 4 4 4 2 3 2 3 1 3 1 6 2 1 -7 3 4 1 2 -8 2 3 20 3 1 -1 3 2 -30
Sample Output
-1 1