跳到主要内容

京都大学 情報学研究科 数理工学専攻 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 eEe \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 SVS \subseteq V and sSs \in S. Among all arcs (u,v)(u,v) going from SS to VSV−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 sVs \in V can be implemented in O(ElogV)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

3V43\le |V| \le 4

and explain how Dijkstra’s algorithm fails.

题目描述

G=(V,E)G=(V,E) 是简单强连通有向图,网络 N=[G,w]N=[G,w] 由给每条弧 eEe\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 中从 uuvv 的简单有向路的最小总权重。回答:

  1. SVS\subseteq VsSs\in S。在所有从 SS 指向 VSV\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. 证明以任意 sVs\in V 为起点的 Dijkstra 算法可在 NN 上实现为 O(ElogV)O(|E|\log|V|) 时间。
  3. 若在 NN 中加入一条负权弧,Dijkstra 算法的输出可能不再是正确的最短距离。构造一个满足 3V43\le |V|\le4 的具体例子,并说明算法如何失效。

考点

  • Dijkstra 算法的正确性:利用非负边权证明跨越已确定顶点集合的最小候选弧能确定新顶点的最短距离。
  • 优先队列复杂度分析:用堆维护暂定距离,说明算法达到 O(ElogV)O(|E|\log|V|)
  • 负权边反例:构造极小有向网络,展示顶点被永久确定后仍可能经负权弧得到更短路径。

Kai

(i)

Take a shortest path from ss to uu^*, 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 vv^* 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 $$Pbeashortestsimplepathfrombe a shortest simple path fromstotov^.Since. Since s \in Sandandv^ \in V - S,thepath, the path Pmustcrossfrommust cross fromStotoV−S$ at least once.

Let (x,y)(x,y) be the first arc of PP that goes from SS to VSV−S. Thus xSx \in S and yVSy \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(VlogV)O(|V| \log |V|)
  • Each arc is relaxed once, and each successful relaxation causes a priority queue update: O(ElogV)O(|E| \log |V|)

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

Thus the total running time is

O(VlogV)+O(ElogV)=O(ElogV)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 sbas \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.