67 lines
2.4 KiB
Text
67 lines
2.4 KiB
Text
---
|
|
id: sp-neg
|
|
title: "Shortest Paths with Negative Edge Weights"
|
|
author: Benjamin Qi
|
|
prerequisites:
|
|
- Gold - Shortest Paths with Non-Negative Edge Weights
|
|
description: Applications of Bellman-Ford.
|
|
frequency: 0
|
|
---
|
|
|
|
import { Problem } from "../models";
|
|
|
|
export const metadata = {
|
|
problems: {
|
|
sam: [
|
|
new Problem("Kattis", "SSSP Negative", "shortestpath3", "Easy", false, [], ""),
|
|
new Problem("Kattis", "APSP (with negative weights)", "allpairspath", "Easy", false, [], ""),
|
|
new Problem("CSES", "(Negative) Cycle Finding", "1197", "Easy", false, [], ""),
|
|
],
|
|
probs: [
|
|
new Problem("SPOJ", "Arbitrage", "ARBITRAG", "Easy", false, [], ""),
|
|
new Problem("CSES", "High Score", "1673", "Easy", false, [], ""),
|
|
],
|
|
linear: [
|
|
new Problem("ojuz", "Restore Array", "RMI19_restore", "Normal", false, [], "similar to [Art](https://codeforces.com/gym/102394/problem/A)"),
|
|
],
|
|
}
|
|
};
|
|
|
|
<problems-list problems={metadata.problems.sam} />
|
|
|
|
<br/>
|
|
|
|
### Tutorial
|
|
|
|
<resources title="SSSP Negative">
|
|
<resource source="CPH" title="13.1"></resource>
|
|
<resource source="cp-algo" title="Bellman-Ford" url="graph/bellman_ford.html"></resource>
|
|
<resource source="cp-algo" title="Finding Negative Cycle" url="finding-negative-cycle-in-graph.html"></resource>
|
|
<resource source="TC" title="Intro to Graphs Section 3" url="introduction-to-graphs-and-their-data-structures-section-3/"></resource>
|
|
</resources>
|
|
|
|
Can also use [Shortest Path Faster Algorithm](https://en.wikipedia.org/wiki/Shortest_Path_Faster_Algorithm) or modify Dijkstra slightly (though the same running time bound no longer applies).
|
|
|
|
(code)?
|
|
|
|
### Problems
|
|
|
|
<problems-list problems={metadata.problems.probs} />
|
|
|
|
## Simple Linear Programming
|
|
|
|
You can also use shortest path algorithms to solve the following problem (a very simple [linear program](https://en.wikipedia.org/wiki/Linear_programming)).
|
|
|
|
> Given variables $x_1,x_2,\ldots,x_N$ with constraints in the form $x_i-x_j\ge c$, compute a feasible solution.
|
|
|
|
<resources>
|
|
<resource source="MIT" title="Slides from Intro to Algorithms" url="https://www.cs.rit.edu/~spr/COURSES/ALG/MIT/lec18.pdf">Linear Programming Trick</resource>
|
|
</resources>
|
|
|
|
**Example:** Timeline (USACO Camp)
|
|
|
|
- equivalent to [Timeline (Gold)](http://www.usaco.org/index.php?page=viewproblem2&cpid=1017) except $N,C\le 5000$ and negative values of $x$ are possible.
|
|
|
|
### Problems
|
|
|
|
<problems-list problems={metadata.problems.linear} />
|