CodeBarn
8/6/2018 - 10:23 AM

Floyd-Warshall's APSP

Floyd-Warshall's APSP DP algorithm for small graphs (V <= 400), runs in O(V^3)

    // Floyd-warshall's APSP, initially g[i][j] is weight of path from i -> j
    // for direct connections given; otherwise INF (0x3f3f3f3f ~ 1 bil).
    // 'g' is represented as an adjacency matrix.  This algorithm is generally
    // useable as long as number of vertices, V <= 400 (approx.)
    REP(k, 101) {
      REP(i, 101) {
        REP(j, 101) { g[i][j] = min(g[i][j], g[i][k] + g[k][j]); }
      }
    }