3.5 KiB
3.5 KiB
id | title | author | prerequisites | ||
---|---|---|---|---|---|
sp | Shortest Paths | Benjamin Qi |
|
- 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
- CSES 13.2
- cp-algo Dijkstra (Dense Graphs)
- cp-algo Dijkstra (Sparse Graphs)
- Usually, it's this one that's applicable.
- CPC.8
Problems
- CSES
- USACO
- Milk Pumping
- fairly standard application
- Shortcut
- Fine Dining
- Milk Pumping
- Other
All Pairs Shortest Path (APSP)
Use the Floyd-Warshall algorithm.
Standard
Tutorial
- CPH 13.3
- cp-algo Floyd-Warshall
Problems
- USACO Moortal Cowmbat
- Use APSP before running DP.
- SPOJ Arbitrage
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 formx_i-x_j\ge c
, compute a feasible solution.
Problems
- General
- Simple Linear Programming
- Restore Array
- Art (basically same as above)
- Timeline (Camp)
- equivalent to Timeline (Gold) except
N,C\le 5000
and negative values ofx
are possible.
- equivalent to Timeline (Gold) except