A potential-based variant of the Bellman-Ford algorithm