#c22607. 最小点数负环
最小点数负环
Minimum-Vertex Negative Cycle
Problem Description
Given a directed weighted simple graph with vertices and edges, with vertices numbered from to , find a cycle with the smallest number of vertices such that the sum of edge weights on the cycle is negative.
Input Format
The first line contains two integers , the number of vertices and edges.
The next lines each contain three integers , meaning there is a directed edge of weight from vertex to vertex .
Output Format
Output one line with an integer: the number of vertices on the smallest negative cycle. If no negative cycle exists, output -1.
Sample Input
3 6
1 2 -2
2 1 1
2 3 -10
3 2 10
3 1 -10
1 3 10
Sample Output
2
Constraints
For of the data: , , , .