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/3_Gold/Gold_SP.md

82 lines
2.6 KiB
Markdown
Raw Normal View History

2020-06-04 01:42:57 +00:00
---
2020-06-04 02:09:42 +00:00
slug: /gold/sp
2020-06-04 01:42:57 +00:00
title: "Gold - Shortest Path"
author: Benjamin Qi
---
2020-06-03 20:56:04 +00:00
# Gold - Shortest Path
Author: Benjamin Qi
[CPC.7](https://github.com/SuprDewd/T-414-AFLV/tree/master/07_graphs_1)
## Breadth First Search
2020-06-03 21:08:42 +00:00
Find the shortest path where all edge weights are 1.
* [CSES Message Route](https://cses.fi/problemset/task/1667)
2020-06-03 20:56:04 +00:00
### Tutorial
- [CSAcademy BFS](https://csacademy.com/lesson/breadth_first_search)
- [cp-algo BFS](https://cp-algorithms.com/graph/breadth-first-search.html)
- [cp-algo 0/1 BFS](https://cp-algorithms.com/graph/01_bfs.html)
### Problems
- [Cow Navigation](http://www.usaco.org/index.php?page=viewproblem2&cpid=695)
- [Dream](http://www.usaco.org/index.php?page=viewproblem2&cpid=575)
- [Lasers](http://www.usaco.org/index.php?page=viewproblem2&cpid=671)
2020-06-03 21:08:42 +00:00
* [Monsters](https://cses.fi/problemset/task/1194)
2020-06-03 20:56:04 +00:00
2020-06-03 21:08:42 +00:00
## Non-Negative Edge Weights
2020-06-03 20:56:04 +00:00
* [Kattis SSSP Non-Negative](https://open.kattis.com/problems/shortestpath1)
2020-06-03 21:08:42 +00:00
* [CSES Shortest Routes I](https://cses.fi/problemset/task/1671)
* [CSES Flight Discount](https://cses.fi/problemset/task/1195)
* [CSES Flight Routes](https://cses.fi/problemset/task/1196)
* [CSES Investigation](https://cses.fi/problemset/task/1202)
2020-06-03 20:56:04 +00:00
2020-06-03 21:08:42 +00:00
Use *Dijkstra's Algorithm*.
2020-06-03 20:56:04 +00:00
2020-06-03 21:08:42 +00:00
### Tutorial
2020-06-03 20:56:04 +00:00
* CSES 13.2
* [cp-algo Dijkstra (Dense Graphs)](https://cp-algorithms.com/graph/dijkstra_sparse.html)
* [cp-algo Dijkstra (Sparse Graphs)](https://cp-algorithms.com/graph/dijkstra_sparse.html)
* Usually, it's this one that's applicable.
2020-06-03 21:08:42 +00:00
### USACO Gold Problems
2020-06-03 20:56:04 +00:00
* [Milk Pumping](http://www.usaco.org/index.php?page=viewproblem2&cpid=969)
* fairly standard application
* [Shortcut](http://usaco.org/index.php?page=viewproblem2&cpid=899)
* [Fine Dining](http://usaco.org/index.php?page=viewproblem2&cpid=861)
2020-06-03 21:08:42 +00:00
## All Pairs Shortest Path (APSP)
2020-06-03 20:56:04 +00:00
2020-06-03 21:08:42 +00:00
* [CSES Shortest Routes II](https://cses.fi/problemset/task/1672)
* [Kattis APSP (with negative weights)](https://open.kattis.com/problems/allpairspath)
2020-06-03 20:56:04 +00:00
Use the *Floyd-Warshall* algorithm.
2020-06-03 21:08:42 +00:00
### Tutorial
2020-06-03 20:56:04 +00:00
* CSES 13.3
* [cp-algo Floyd-Warshall](https://cp-algorithms.com/graph/all-pair-shortest-path-floyd-warshall.html)
2020-06-03 21:08:42 +00:00
### USACO Gold Problems
2020-06-03 20:56:04 +00:00
* [Moortal Cowmbat](http://usaco.org/index.php?page=viewproblem2&cpid=971)
* Use APSP before running DP.
2020-06-03 21:08:42 +00:00
## Negative Edge Weights
2020-06-03 20:56:04 +00:00
Hasn't appeared in recent USACO Gold as far as I know.
2020-06-03 21:08:42 +00:00
* [CSES High Score](https://cses.fi/problemset/task/1673)
2020-06-03 20:56:04 +00:00
* [Kattis SSSP Negative](https://open.kattis.com/problems/shortestpath3)
2020-06-03 23:46:28 +00:00
* [CSES Cycle Finding](https://cses.fi/problemset/task/1197)
2020-06-03 20:56:04 +00:00
2020-06-03 21:08:42 +00:00
Can also modify Dijkstra's so it works with negative edge weights (but not negative cycles). The same running time bound no longer applies.