跳到主要内容

京都大学 情報学研究科 数理工学専攻 2016年8月実施 グラフ理論

Author​

祭音Myyura

Description​

大学公表の原題 Let G=(V,E)G=(V,E) be a simple strongly connected directed graph. Let N=[G,w]N=[G,w] be a network obtained by assigning a nonnegative real weight w(e)w(e) to each arc e∈Ee \in E. An arc from vertex u to vertex v is denoted by (u,v)(u,v), and its weight is also denoted by w(u,v)w(u,v). Define dist(u,v)\text{dist}(u,v) as the minimum total weight of a simple directed path from uu to vv in NN.

Answer the following questions.

(i) Let S⊆VS \subseteq V and s∈Ss \in S. Among all arcs (u,v)(u,v) going from SS to V−SV−S, choose an arc (u∗,v∗)(u^*, v^*) minimizing

dist(s,u)+w(u,v).\text{dist}(s,u)+w(u,v).

Prove that

dist(s,v∗)=dist(s,u∗)+w(u∗,v∗).\text{dist}(s,v^∗)=\text{dist}(s,u^∗)+w(u^∗,v^∗).

(ii) Show that Dijkstra’s algorithm from a starting vertex s∈Vs \in V can be implemented in O(∣E∣log⁡∣V∣)O(|E| \log |V|) time on NN.

(iii) If one arc with negative weight is added to NN, the values output by Dijkstra’s algorithm may fail to be correct shortest distances. Construct a concrete example with

3≤∣V∣≤43\le |V| \le 4

and explain how Dijkstra’s algorithm fails.

题目描述​

设 G=(V,E)G=(V,E) 是简单强连通有向图,网络 N=[G,w]N=[G,w] 由给每条弧 e∈Ee\in E 赋予非负实权 w(e)w(e) 得到。用 (u,v)(u,v) 表示从顶点 uu 指向 vv 的弧,其权重也记作 w(u,v)w(u,v);dist⁡(u,v)\operatorname{dist}(u,v) 定义为 NN 中从 uu 到 vv 的简单有向路的最小总权重。回答:

  1. 设 S⊆VS\subseteq V、s∈Ss\in S。在所有从 SS 指向 V∖SV\setminus S 的弧 (u,v)(u,v) 中,选取使
    dist⁡(s,u)+w(u,v)\operatorname{dist}(s,u)+w(u,v)
    最小的 (u∗,v∗)(u^*,v^*)。证明
    dist⁡(s,v∗)=dist⁡(s,u∗)+w(u∗,v∗).\operatorname{dist}(s,v^*)= \operatorname{dist}(s,u^*)+w(u^*,v^*).
  2. 证明以任意 s∈Vs\in V 为起点的 Dijkstra 算法可在 NN 上实现为 O(∣E∣log⁡∣V∣)O(|E|\log|V|) 时间。
  3. 若在 NN 中加入一条负权弧,Dijkstra 算法的输出可能不再是正确的最短距离。构造一个满足 3≤∣V∣≤43\le |V|\le4 的具体例子,并说明算法如何失效。

Kai​

(i)​

Take a shortest path from ss to u∗u^*, and then append the arc (u∗,v∗)(u^*, v^*). If this walk repeats vertices, we may delete cycles. Since all edge weights are nonnegative, deleting cycles cannot increase the total weight. Hence there is a simple path from ss to v∗v^* of weight at most

dist(s,u∗)+w(u∗,v∗).\text{dist}(s,u^∗)+w(u^∗,v^∗).

i.e.,

dist(s,v∗)≤dist(s,u∗)+w(u∗,v∗).\text{dist}(s,v^∗) \le \text{dist}(s,u^∗)+w(u^∗,v^∗).

Now we prove the reverse inequality.

Let PP be a shortest simple path from ss to v∗v^*. Since s∈Ss \in S and v∗∈V−Sv^* \in V - S, the path PP must cross from SS to V−SV−S at least once.

Let (x,y)(x,y) be the first arc of PP that goes from SS to V−SV−S. Thus x∈Sx \in S and y∈V−Sy \in V−S. The part of PP from ss to xx has weight at least dist(s,x)\text{dist}(s,x). Also, all edge weights after yy are nonnegative. Hence

dist(s,v∗)≥dist(s,x)+w(x,y)\text{dist}(s, v^*) \ge \text{dist}(s, x) + w(x, y)

By the choice of (u∗,v∗)(u^*, v^*),

dist(s,u∗)+w(u∗,v∗)≤dist(s,x)+w(x,y)\text{dist}(s,u^∗)+w(u^∗,v^∗) \le \text{dist}(s, x) + w(x, y)

Hence,

dist(s,v∗)≥dist(s,u∗)+w(u∗,v∗)\text{dist}(s, v^*) \ge \text{dist}(s,u^∗)+w(u^∗,v^∗)

Combining the two inequalities, we get

dist(s,v∗)=dist(s,u∗)+w(u∗,v∗).\text{dist}(s,v^∗)=\text{dist}(s,u^∗)+w(u^∗,v^∗).

(ii)​

Use an adjacency-list representation and a binary heap priority queue supporting Extract-Min and Decrease-Key, the pseudocode of Dijkstra algorithm is given as follows:

Dijkstra(G, w, s):

for each vertex v in V:
d[v] = infinity
parent[v] = NIL

d[s] = 0

S = empty set
Q = priority queue containing all vertices v, keyed by d[v]

while Q is not empty:

u = Extract-Min(Q)

add u to S
// At this moment, d[u] is fixed.
// It will never be changed again.

for each outgoing arc (u, v) in Adj[u]:

if v is not in S:
if d[v] > d[u] + w(u, v):
d[v] = d[u] + w(u, v)
parent[v] = u
Decrease-Key(Q, v, d[v])

return d, parent

For the time complexity

  • Each vertex is extracted from the priority queue once: O(∣V∣log⁡∣V∣)O(|V| \log |V|)
  • Each arc is relaxed once, and each successful relaxation causes a priority queue update: O(∣E∣log⁡∣V∣)O(|E| \log |V|)

As the directed graph is strongly connected, we have ∣E∣≥∣V∣|E| \geq |V| when ∣V∣≥2|V| \ge 2.

Thus the total running time is

O(∣V∣log⁡∣V∣)+O(∣E∣log⁡∣V∣)=O(∣E∣log⁡∣V∣)O(|V| \log |V|) + O(|E| \log |V|) = O(|E| \log |V|)

(iii)​

The true shortest distance from ss to aa is 2+(−3)=−12 + (-3) = -1 using the path s→b→as \to b \to a.

Now run Dijkstra’s algorithm from ss.

Initially,

dist(s)=0,dist(a)=∞,dist(b)=∞.\text{dist}(s) = 0, \text{dist}(a) = \infty, \text{dist}(b) = \infty.

After processing ss,

dist(a)=1,dist(b)=2.\text{dist}(a) = 1, \text{dist}(b) = 2.

Dijkstra chooses a next because dist(a)=1<dist(b)=2\text{dist}(a) = 1 < \text{dist}(b) = 2. It fixes dist(a)=1\text{dist}(a) = 1, but the true distance is dist(a)=−1\text{dist}(a) = -1.

Therefore Dijkstra’s algorithm fails when a negative-weight edge is allowed.