跳到主要内容

京都大学 情報学研究科 数理工学専攻 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.

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.