APSP, Negative Triangle and Subcubic Equivalence
All-pairs shortest paths on an -vertex graph with real or integer weights takes time with Floyd-Warshall (The Floyd-Warshall Algorithm) or runs of Dijkstra on dense graphs. Decades of work brought only subpolynomial improvements: the fastest algorithm, by Williams (2014), runs in time. The third pillar of fine-grained complexity is the conjecture that no truly subcubic algorithm exists, and the remarkable discovery that many problems that look easier, some with a yes/no answer, are equivalent to APSP under subcubic reductions.
The APSP conjecture
APSP conjecture. For every , APSP on -vertex graphs with integer edge weights in (for some constant ) and no negative cycles has no algorithm.
The weights matter: with small integer weights (bounded by a constant), fast matrix multiplication gives subcubic algorithms (for undirected unweighted graphs, Seidel, 1995: , where is the matrix multiplication exponent). The conjecture is about the general weighted case, where the algebra of resists the tricks of ordinary matrix multiplication.
The min-plus product
The min-plus (distance) product of matrices and is
It is the matrix multiplication of the semiring, computed naively in time, and APSP is equivalent to it (Shortest Paths as Matrix Multiplication):
- APSP from min-plus: with the weight matrix (0 on the diagonal), holds shortest paths of at most edges, so squarings give all distances. A subcubic min-plus product gives subcubic APSP (a factor is absorbed by the ).
- Min-plus from APSP: build a three-layer graph with vertices , , , edges of weight and of weight ; the distance from to is . The graph has vertices.
The program checks both directions on small random matrices.
import random
INF = float("inf")
def min_plus(A, B):
n = len(A)
return [[min(A[i][k] + B[k][j] for k in range(n)) for j in range(n)] for i in range(n)]
def floyd_warshall(W):
n = len(W)
D = [row[:] for row in W]
for k in range(n):
for i in range(n):
for j in range(n):
if D[i][k] + D[k][j] < D[i][j]:
D[i][j] = D[i][k] + D[k][j]
return D
rng = random.Random(4)
n = 12
W = [[0 if i == j else (rng.randint(1, 20) if rng.random() < 0.4 else INF) for j in range(n)] for i in range(n)]
D, squarings = W, 0
while 2 ** squarings < n - 1: # paths of at most 2^t edges after t squarings
D = min_plus(D, D)
squarings += 1
print("APSP by", squarings, "min-plus squarings equals Floyd-Warshall:", D == floyd_warshall(W))
A = [[rng.randint(-9, 9) for _ in range(n)] for _ in range(n)]
B = [[rng.randint(-9, 9) for _ in range(n)] for _ in range(n)]
G = [[INF] * (3 * n) for _ in range(3 * n)] # layers I = 0..n-1, K = n..2n-1, J = 2n..3n-1
for v in range(3 * n):
G[v][v] = 0
for i in range(n):
for k in range(n):
G[i][n + k] = A[i][k]
G[n + i][2 * n + k] = B[i][k]
D3 = floyd_warshall(G)
print("min-plus product read off a 3-layer APSP instance:",
all(D3[i][2 * n + j] == min_plus(A, B)[i][j] for i in range(n) for j in range(n)))APSP by 4 min-plus squarings equals Floyd-Warshall: True
min-plus product read off a 3-layer APSP instance: True
The three-layer graph has negative edges but no cycles at all, so shortest paths are well defined.
Negative triangle
NEGATIVE TRIANGLE. Given an -vertex graph with integer edge weights, are there vertices with ?
It is a yes/no question, and it looks easier than APSP: one bit of output instead of numbers. The easy direction is clear: compute , then check whether for some pair. The surprise is the other direction.
Theorem (Vassilevska Williams and Williams, 2010; stated). NEGATIVE TRIANGLE has an algorithm for some if and only if APSP does (with polynomially bounded weights).
Idea of the hard direction (sketch). To compute the min-plus product , it suffices to find, for every pair , the value . Guess thresholds and ask, for all pairs at once, whether : with , , this is a negative triangle question about the pair . A parallel binary search over the thresholds needs rounds. The key step is to find all pairs involved in negative triangles, not just one, using a subcubic detection algorithm on many small subgraphs: split the vertex set into blocks of size and repeatedly detect and remove triangles block by block. The bookkeeping keeps the total time subcubic.
The program checks the easy direction against brute force, counting the basic operations of each.
import random
def brute_negative_triangle(W):
n, ops = len(W), 0
for i in range(n):
for j in range(i + 1, n):
for k in range(j + 1, n):
ops += 1
if W[i][j] + W[j][k] + W[k][i] < 0:
return (i, j, k), ops
return None, ops
def via_min_plus(W):
n, ops = len(W), 0
for i in range(n):
for j in range(n):
if i == j:
continue
best = None
for k in range(n):
if k != i and k != j:
ops += 1
s = W[i][k] + W[k][j]
best = s if best is None or s < best else best
if best + W[j][i] < 0: # C_ij + w(j, i) < 0
return (i, j), ops
return None, ops
rng = random.Random(7)
print(" n shift brute force via min-plus")
for n, shift in [(20, 0), (20, 70), (30, 85), (30, 100)]:
W = [[0] * n for _ in range(n)]
for i in range(n):
for j in range(i + 1, n):
W[i][j] = W[j][i] = rng.randint(-100, 100) + shift
t1, o1 = brute_negative_triangle(W)
t2, o2 = via_min_plus(W)
print(f"{n:3} {shift:5} {str(t1):12} {o1:6} {str(t2):9} {o2:6}") n shift brute force via min-plus
20 0 (0, 1, 2) 1 (0, 1) 18
20 70 (0, 4, 19) 66 (0, 4) 72
30 85 (0, 16, 26) 325 (0, 16) 448
30 100 None 4060 None 24360
The shift makes all weights larger, so negative triangles become rare; at shift 100 three weights of at least 0 cannot sum below zero, none exists and both methods do their full cubic work. The min-plus version visits ordered triples, six times as many as brute force, but it computes all of on the way, which is what the reductions exploit. Both answers always agree on whether a negative triangle exists.
In C++
Negative triangle detection with the min-plus formulation on a 300-vertex complete graph, weights uniform in plus a shift that makes negative triangles rare: the scan over pairs with an inner minimum over is the cubic loop that the APSP conjecture says cannot be beaten by a polynomial factor.
#include <algorithm>
#include <climits>
#include <cstdio>
#include <vector>
int main() {
const int n = 300;
unsigned s = 5;
auto rnd = [&](int m) { s = s * 1103515245u + 12345u; return int((s >> 8) % m); };
for (int shift : {800, 930, 1000}) {
std::vector<std::vector<int>> w(n, std::vector<int>(n, 0));
for (int i = 0; i < n; i++)
for (int j = i + 1; j < n; j++) w[i][j] = w[j][i] = rnd(2001) - 1000 + shift;
long long ops = 0;
int fi = -1, fj = -1, fk = -1;
for (int i = 0; i < n && fi < 0; i++)
for (int j = 0; j < n && fi < 0; j++) {
if (i == j) continue;
int best = INT_MAX, arg = -1;
for (int k = 0; k < n; k++) {
if (k == i || k == j) continue;
ops++;
if (w[i][k] + w[k][j] < best) { best = w[i][k] + w[k][j]; arg = k; }
}
if (best + w[j][i] < 0) { fi = i; fj = j; fk = arg; }
}
if (fi >= 0)
std::printf("shift %d: negative triangle (%d, %d, %d) of weight %d after %lld steps\n", shift, fi, fk, fj,
w[fi][fk] + w[fk][fj] + w[fj][fi], ops);
else
std::printf("shift %d: no negative triangle after %lld steps (n^3 = %lld)\n", shift, ops, (long long)n * n * n);
}
}shift 800: negative triangle (0, 92, 2) of weight -1 after 596 steps
shift 930: negative triangle (0, 103, 26) of weight -31 after 7748 steps
shift 1000: no negative triangle after 26730600 steps (n^3 = 27000000)
The APSP equivalence class
Vassilevska Williams and Williams (2010), with later additions (stated), showed that the following are equivalent under subcubic reductions: each has an algorithm iff all do.
| Problem | Output |
|---|---|
| APSP; min-plus product | numbers |
| negative triangle | one bit |
| metricity: does a matrix satisfy the triangle inequality? | one bit |
| second shortest simple path between two vertices | one number |
| replacement paths: shortest - path avoiding each edge of a shortest path | numbers |
| minimum weight cycle in a directed or undirected graph (Roditty and Vassilevska Williams, 2011) | one number |
| radius; median (Abboud, Grandoni and Vassilevska Williams, 2015) | one number |
Diameter is notably not known to be in this class: it reduces to APSP, but no reduction in the other direction is known. Its approximation hardness instead comes from SETH via orthogonal vectors (Roditty and Vassilevska Williams, 2013), a reminder that the different conjectures govern different problems.
Test yourself
How does APSP reduce to the min-plus product?
- By one product
- By repeated squarings of the weight matrix
- By products
- It does not
Why is the equivalence of negative triangle and APSP surprising?
- Because negative triangle is NP-hard
- Because a one-bit decision problem turns out to be exactly as hard, up to subcubic factors, as computing distances
- Because APSP is linear
- Because triangles have three vertices
How is negative triangle solved from the min-plus product ?
- Check whether some
- Check whether is symmetric
- Check the diagonal of
- Compute the determinant
Which statement about the APSP conjecture is correct?
- It is proven
- It concerns graphs with polynomially bounded integer weights; small constant weights allow subcubic algorithms via fast matrix multiplication
- It implies P NP
- It forbids algorithms