Rewrite Bellman-Ford and min-cost flow, especially to stop the latter from crashing.