Write a program that, given a directed graph with positive and/or negative costs at the arcs, detects if there is a negative cycle in the graph.
Input consists of several cases. Every case begins with the number of vertices and the number of arcs . Follow triples , indicating that there is an arc of cost , where , . Assume , , and that for every pair of vertices and there is at most one arc of the kind . All numbers are integers. Vertices are numbered from 0 to .
For every case, print "YES" if there is a negative cycle in the graph, and "NO" otherwise.
Input
4 4
0 3 6
1 0 4
3 1 -11
1 2 -6
4 4
0 3 6
1 0 4
3 1 2
1 2 -6
2 2
0 1 10
1 0 10
2 2
0 1 10
1 0 -20
2 2
0 1 10
1 0 -10
Output
YES NO NO YES NO