|
|
вернуться в форумBig Hint Let 0,1,2,..N-1 - outer door N .. 2*N - 1 - 1-inner room doors 2*N .. 3N - 1 - 2-inner room doors .... i*N i*N + 1, .. i*N + N-1 - i-th room doors total (K+1)*N doors. W[i][j] - minimum dist from i to j-th door, where 0 <= i,j < (K+1)*N initially W[i][i] = 0, W[i][j] = inifinity for i <> j. read, and set W[i][j] = 1 if there exists road from i to j doors. ----------------- N times run following steps: 1. Floyd algorithm for 0.. (K+1)*N - 1 doors.
2. for 1<= t <= K , 0 <= i, j < N update W[t*N + i][ t*N + j] = min(W[t*N + i][t*N+j], W[i][j]) Because (t*N + i, t*N + j) - is identical path as outer (i,j) path.
Edited by author 31.10.2020 16:46 |
|
|