Shortest path with a fixed number of edges

后端 未结 5 1299
陌清茗
陌清茗 2021-02-03 16:28

Find the shortest path through a graph in efficient time, with the additional constraint that the path must contain exactly n nodes.

We have a directed, weighte

5条回答
  •  日久生厌
    2021-02-03 17:05

    let say we want shortest distance from node x to y of k step simple dp solution would be

    A[k][x][y] = min over { A[1][i][k] + A[t-1][k][y] } k varies from 0 to n-1

    A[1][i][j] = r[i][j]; p[1][i][j]=j;
    for(t=2; t<=n; t++)
    for(i=0; i

提交回复
热议问题