This repository has been archived on 2022-06-22. You can view files and clone it, but cannot push or open issues or pull requests.
usaco-guide/content/5_Gold/4_Gold_SP.md
2020-06-15 16:19:07 -07:00

3.5 KiB

id title author prerequisites
sp Shortest Paths Benjamin Qi
Gold - Breadth First Search
  • Shortest Path Without Negative Edge Weights
  • Shortest Path With Negative Edge Weights
  • All Pairs Shortest Path

Non-Negative Edge Weights

Use Dijkstra's Algorithm.

Standard

Tutorial

Problems

All Pairs Shortest Path (APSP)

Use the Floyd-Warshall algorithm.

Standard

Tutorial

Problems

Negative Edge Weights

  • Hasn't appeared in recent USACO Gold as far as I know.
  • Usually Bellman-Ford is used.
  • If no negative cycles, can use Shortest Path Faster Algorithm or modify Dijkstra slightly (though the same running time bound no longer applies).

Tutorial

You can also use shortest path algorithms to solve the following problem (a very simple linear program).

Given variables x_1,x_2,\ldots,x_N with constraints in the form x_i-x_j\ge c, compute a feasible solution.

Problems