One more round finds the loop
transcript
A route can pay you to loop. Then no cheapest cost exists. Each loop lowers it again. How do you detect that? Run one more round.
A route without a loop has few edges. At most n minus one. So n minus one rounds settle every route. Anything after that is a loop.
Costs after five rounds. Round six still lowers hub two. A loop must pay. Hub three is reached from hub two. So hub three is unbounded as well.
Mark the hubs that drop. Then mark every hub they reach. Those have no cheapest cost at all. Report them as unbounded.
A thousand vertices, five thousand edges. That is 4,995,000 relaxations, which is fast enough.
Unreached means no cost yet. Never add a fee to it. Check it before every relax.
Run n minus one rounds first. Then run one more round. A drop means a negative cycle. Full breakdown in the lecture.