Bellman–Ford shortest paths · Compiler

Bellman–Ford shortest paths

Report the estimate for t after exactly k Bellman-Ford scans. Initially only s has a finite estimate, 0. In each scan process edges in input order. For each edge from u to v with finite estimate at u, replace v's estimate if the cost via u is lower. An update takes effect immediately.

Input
The first line contains n m s t k. Vertices are numbered 0 through n-1 (1 <= n <= 50, 0 <= m <= 200). Each of the next m lines contains u v w for an edge from u to v. Endpoints differ and each ordered pair occurs at most once. Both s and t are vertex IDs, 0 <= k < n, and each weight w is an integer from -100 to 100. The graph has no negative-cost cycle.
Output
Print the estimate at t after the last scan (or after initialization when k is 0). Print INF if it is still infinite.

Compiler Explorer runs your code when you run or check it.

Loading your exercise draft…