Write a program that, given a directed graph with postive and/or negative costs at the arcs (but no negative cycles), and two vertices and , computes the minimum cost to go from to .
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 , and . Finally, we have and . 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 . The directed graph has no negative cycles.
For every case, print the minimum cost to go from to , if this is possible. If there is no path from to , state so.
Input
6 10
1 0 6
1 5 15
3 4 3
3 1 8
4 0 20
0 5 5
0 2 1
5 1 10
4 1 2
2 3 4
3 5
2 1
0 1 1000
1 0
8 11
0 1 10
0 7 8
1 5 2
2 1 1
2 3 1
3 4 3
4 5 -1
5 2 -2
6 5 -1
6 1 -4
7 6 1
0 1
Output
16 no path from 1 to 0 5