出典:大学公式問題冊子の保存版。
Given a directed graph G=(V,E), we would like to find all-pairs shortest path lengths which are the all shortest path lengths between every pair of vertices, where the size of the set V,∣V∣=n. Let euv denote a directed edge from a vertex u to a vertex v, and δuv denote the length of the edge euv. The graph G may have a negative length edge but does not have any negative length cycle. The length of the edge from the vertex u to the same vertex u,δuu=0, and when there exists no edge from the vertex u to the vertex v, δuv=∞.
Algorithm 1 on the next page outputs the single-source shortest path lengths. Let s∈V be a single source vertex, the shortest path length from the vertex s to a vertex v∈V is stored in d(v). Algorithm 2 outputs the all-pairs shortest path lengths table D, where the length of the shortest path from a vertex u to a vertex v is stored in D(u,v). Each algorithm uses d(k) and D(k)(k=0,1,…) to store interim results, respectively. Answer the following questions.
(1) Apply Algorithm 1 to the graph G1=(V1,E1) in Figure 1 to obtain the shortest path length from a single-source vertex v0. Table 1 shows d(0) in Algorithm 1. Show the single-source path length d(1),d(2),d(3), and d(4) from the single-source vertex v0.
(2) Apply Algorithm 2 to the graph G1=(V1,E1) in Figure 1 to obtain the all-pairs shortest path lengths. Table 2 shows D(0) in Algorithm 2. Show the selected vertex w∈V1 in the Main Loop and the corresponding table D(1),D(2),D(3),D(4), and D(5).
(3) To obtain all-pairs shortest path lengths, consider Algorithm 1-ALL which applies Algorithm 1 for all vertices in V as a single-source vertex. Compare Algorithm 1-ALL and Algorithm 2.
Table 1: d(0) in Algorithm 1
destination
v0
0
v1
∞
v2
∞
v3
∞
v4
∞
Table 2: D(0) in Algorithm 2
source\destination
v0
v1
v2
v3
v4
v0
0
1
∞
5
9
v1
∞
0
1
3
∞
v2
∞
∞
0
-1
∞
v3
∞
1
∞
0
1
v4
1
∞
∞
∞
0
Algorithm definitions — independent English summary
This is an independent summary of the algorithm definitions.
Algorithm 1: initialize d(0)(s)=0 and d(0)(v)=∞ for v=s, and perform n−1 rounds of edge relaxation. The printed assignment for each edge euv is
d(k)(v)=min{d(k−1)(v),d(k−1)(u)+δuv}.
For the shortest-path calculation below, initialize d(k)←d(k−1), and for each edge accumulate
d(k)(v)←min{d(k)(v),d(k−1)(u)+δuv}.
The answer below uses this accumulating relaxation.
Algorithm 2: initialize D(0)(u,v)=δuv. Select each vertex w once, and use the preceding matrix to form
D(k+1)(u,v)=min{D(k)(u,v),D(k)(u,w)+D(k)(w,v)}
for all u,v, then increment k. The order of the selected vertices must be stated when giving intermediate matrices.