跳到主要内容

東京大学 情報理工学系研究科 創造情報学専攻 2009年8月実施 筆記試験 第1問

Author

itsuitsuki

Description

Given a directed graph G=(V,E)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=nV, |V| = n. Let euve_{uv} denote a directed edge from a vertex uu to a vertex vv, and δuv\delta_{uv} denote the length of the edge euve_{uv}. The graph GG may have a negative length edge but does not have any negative length cycle. The length of the edge from the vertex uu to the same vertex u,δuu=0u, \delta_{uu} = 0, and when there exists no edge from the vertex uu to the vertex vv, δuv=\delta_{uv} = \infty.

Algorithm 1 on the next page outputs the single-source shortest path lengths. Let sVs \in V be a single source vertex, the shortest path length from the vertex ss to a vertex vVv \in V is stored in d(v)d(v). Algorithm 2 outputs the all-pairs shortest path lengths table DD, where the length of the shortest path from a vertex uu to a vertex vv is stored in D(u,v)D(u, v). Each algorithm uses d(k)d^{(k)} and D(k)(k=0,1,)D^{(k)} (k = 0, 1, \dots) to store interim results, respectively. Answer the following questions.

(1) Apply Algorithm 1 to the graph G1=(V1,E1)G_1 = (V_1, E_1) in Figure 1 to obtain the shortest path length from a single-source vertex v0v_0. Table 1 shows d(0)d^{(0)} in Algorithm 1. Show the single-source path length d(1),d(2),d(3)d^{(1)}, d^{(2)}, d^{(3)}, and d(4)d^{(4)} from the single-source vertex v0v_0.

(2) Apply Algorithm 2 to the graph G1=(V1,E1)G_1 = (V_1, E_1) in Figure 1 to obtain the all-pairs shortest path lengths. Table 2 shows D(0)D^{(0)} in Algorithm 2. Show the selected vertex wV1w \in V_1 in the Main Loop and the corresponding table D(1),D(2),D(3),D(4)D^{(1)}, D^{(2)}, D^{(3)}, D^{(4)}, and D(5)D^{(5)}.

(3) To obtain all-pairs shortest path lengths, consider Algorithm 1-ALL which applies Algorithm 1 for all vertices in VV as a single-source vertex. Compare Algorithm 1-ALL and Algorithm 2.

Table 1: d(0)d^{(0)} in Algorithm 1

destination
v0v_00
v1v_1\infty
v2v_2\infty
v3v_3\infty
v4v_4\infty

Table 2: D(0)D^{(0)} in Algorithm 2

source\destinationv0v_0v1v_1v2v_2v3v_3v4v_4
v0v_001\infty59
v1v_1\infty013\infty
v2v_2\infty\infty0-1\infty
v3v_3\infty1\infty01
v4v_41\infty\infty\infty0

题目描述

给定含 n=Vn=|V| 个顶点的有向图 G=(V,E)G=(V,E),求任意两顶点之间的最短路径长度。用 euve_{uv} 表示从 uuvv 的有向边,δuv\delta_{uv} 表示其长度。图中允许负权边,但不存在负权环;约定 δuu=0\delta_{uu}=0,若 uuvv 无边,则 δuv=\delta_{uv}=\infty

原文所给算法 1 求单源最短路:源点为 sVs\in Vd(v)d(v) 存储 ssvv 的最短距离,并用 d(k)d^{(k)} 存储中间结果。算法 2 求全源最短路矩阵 DD,其中 D(u,v)D(u,v) 存储 uuvv 的最短距离,并用 D(k)D^{(k)} 存储中间结果。

  1. 对图 1 的 G1=(V1,E1)G_1=(V_1,E_1),以 v0v_0 为源点执行算法 1。初值表为

    终点d(0)d^{(0)}
    v0v_000
    v1v_1\infty
    v2v_2\infty
    v3v_3\infty
    v4v_4\infty

    写出 d(1),d(2),d(3),d(4)d^{(1)},d^{(2)},d^{(3)},d^{(4)}

  2. 对同一图执行算法 2。初始矩阵为

    源点 \ 终点v0v_0v1v_1v2v_2v3v_3v4v_4
    v0v_00011\infty5599
    v1v_1\infty001133\infty
    v2v_2\infty\infty001-1\infty
    v3v_3\infty11\infty0011
    v4v_411\infty\infty\infty00

    写出主循环各轮选中的 wV1w\in V_1,以及相应的 D(1),D(2),D(3),D(4),D(5)D^{(1)},D^{(2)},D^{(3)},D^{(4)},D^{(5)}

  3. 定义算法 1-ALL:把 VV 中每个顶点依次作为源点运行算法 1,以得到全源最短路。比较算法 1-ALL 与算法 2。算法正文及图 G1G_1 沿用原文图片。