Skip to content

Instantly share code, notes, and snippets.

@benjaminion
Last active November 4, 2017 18:08
Show Gist options
  • Save benjaminion/419d25c1643e803bd2d21f0d5e1aa96c to your computer and use it in GitHub Desktop.
Save benjaminion/419d25c1643e803bd2d21f0d5e1aa96c to your computer and use it in GitHub Desktop.
Optimising APSP
int a; int b; int c;
for (k = 0; k < n; ++k) {
for (i = 0; i < n; ++i) {
a = d[i * n + k];
if (a == INF) continue;
for (j = 0; j < n; ++j) {
b = d[i * n + j];
c = d[k * n + j];
if (c == INF) continue;
else if (b == INF) d[i * n + j] = a + c;
else d[i * n + j] = a < b + c ? a : b + c;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment