跳到主要内容

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

Author

祭音Myyura

Description

日本語版

G=(V,E)G=(V, E) を節点集合 VV、 枝集合 EE から成る単純強連結有向グラフとし、VV に属する節点の個数を nnEEに属する枝の本数を mm とする。 GG の各枝 eEe \in E に実数値重み w(e)w(e) を与えて得られるネッタワークを N=[G,w]N=[G, w] とする。 節点 uu から節点 vv への有向枝は (u,v)(u,v) と書き、その枝重みは w(u,v)w(u,v) とも書く。 節点 v1,v2,,vkv_1, v_2, \ldots, v_k をこの順に訪ねる路 P=(v1,v2,,vk)P= (v_1, v_2, \ldots, v_k) について、枝の本数を μ(P)k1\mu(P) \triangleq k-1、枝重みの和を ω(P)i=1k1w(vi,vi+1)\omega(P) \triangleq \sum_{i=1}^{k-1} w(v_i, v_{i+1}) と書く。

節点 sVs\in V が与えられたものとする。各節点 vVv\in V について、ss から vv への路 PPμ(P)n1\mu(P) \le n-1 を満たすものにおける ω(P)\omega(P) のうち、最小値を d(v)d(v) と定める。 また ss から vv への単純路 SS における ω(S)\omega(S) のうち、最小値を d(v)d^*(v) と定める。 ω(C)<0\omega(C) < 0 を満たす閉路 CC を負閉路と呼ぶ。以下の問いに答えよ。

(i) NN に負閉路が存在しないとき、かつその時に限り、

d(u)+w(u,v)d(v),  (u,v)Ed(u) + w(u, v) \ge d(v), \ \ \forall (u,v)\in E

が成り立つことを示せ。

(ii) NN に負閉路が存在するかどうかを判定し、もし存在しない場合には全ての vVv \in V に対して d(v)d^*(v) を出力する、O(mn)O(mn) 時間のアルゴリズムを与えよ。

English Version

Let G=(V,E)G=(V, E) denote a simple, strongly connected digraph with a vertex set VV and an edge set EE, let nn denote the number of vertices in VV, and let mm denote the number of edges in EE. Let N=[G,w]N=[G, w] denote a network obtained from GG by assigning a real value w(e)w(e) to each edge eEe \in E as its weight. A directed edge from a vertex uu to a vertex vv is denoted by (u,v)(u,v) and its weight is written as w(u,v)w(u,v). When a path P=(v1,v2,,vk)P= (v_1, v_2, \ldots, v_k) visits vertices v1,v2,,vkv_1, v_2, \ldots, v_k in this order, let μ(P)k1\mu(P) \triangleq k-1 denote the number of edges in PP and let ω(P)i=1k1w(vi,vi+1)\omega(P) \triangleq \sum_{i=1}^{k-1} w(v_i, v_{i+1}) denote the summation of weights of edges in PP

Suppose that a vertex sVs\in V is given. For each vertex vVv\in V, we define d(v)d(v) to be the minimum of ω(P)\omega(P) among all paths PP from ss to vv such that μ(P)n1\mu(P) \le n-1. We define d(v)d^*(v) to be the minimum of ω(S)\omega(S) among all simple paths SS from ss to vv. A cycle CC is called a negative cycle if ω(C)<0\omega(C) < 0. Answer the following questions.

(i) Prove that there is no negative cycle in NN if and only if

d(u)+w(u,v)d(v),  (u,v)Ed(u) + w(u, v) \ge d(v), \ \ \forall (u,v)\in E

(ii) Show an O(mn)O(mn)-time algorithm that determines whether or not there exists a negative cycle in NN and that outputs d(v)d^*(v) for all vVv \in V if no negative cycle exists.

Kai

(i)

(a) \Rightarrow (If there is no negative cycle, then d(u)+w(u,v)d(v),(u,v)Ed(u) + w(u, v) \ge d(v), \forall (u,v)\in E)

Prove by contradiction: Assume that there exists an edge (u,v)E(u', v') \in E such that d(u)+w(u,v)<d(v)d(u') + w(u', v') < d(v').

Let Pu=(s,u1,u2,,u)P_{u'} = (s, u_1, u_2, \ldots, u') denote a path from ss to uu' of weights ω(Pu)=d(u)\omega(P_{u'}) = d(u') and Pv=(s,v1,v2,,v)P_{v'} = (s, v_1, v_2, \ldots, v') denote a path from ss to vv' of weights ω(Pv)=d(v)\omega(P_{v'}) = d(v').

Let Puv=(s,u1,u2,,u,v)P_{u'v'} = (s, u_1, u_2, \ldots, u', v'). Since d(v)>d(u)+w(u,v)d(v') > d(u') + w(u', v'), by the definition of d(v)d(v') we know that μ(Puv)>n1\mu(P_{u'v'}) > n - 1, i.e., PuvP_{u'v'} is not a simple path.

W.l.o.g we assume that Puv=(s,u1,u2,,uk,uk+1,,uk+i,uk,,u,v)P_{u'v'} = (s, u_1, u_2, \ldots, u_k, u_{k+1}, \ldots, u_{k+i}, u_k, \ldots, u', v') only contains 11 sub-cycle C=(uk,uk+1,,uk+i,uk)C' = (u_k, u_{k+1}, \ldots, u_{k+i}, u_k).

Assume that ω(C)0\omega(C') \ge 0, let Pv=(s,u1,u2,,uk,,u,v)P_{v'}^{'} = (s, u_1, u_2, \ldots, u_k, \ldots, u', v') denote the path obtained by remove the sub-cycle CC' of PuvP_{u'v'}, we have

ω(Pv)=ω(Puv)ω(C)=d(u)+w(u,v)ω(C)<d(v)ω(C)\begin{aligned} \omega(P_{v'}^{'}) &= \omega(P_{u'v'}) - \omega(C') \\ &= d(u') + w(u', v') - \omega(C') \\ &< d(v') - \omega(C') \end{aligned}

and μ(Pv)n1\mu(P_{v'}^{'}) \le n - 1, which is contradictory to the definition of d(v)d(v').

Hence ω(C)<0\omega(C') < 0, which is contradictory to the condition "there is no negative cycle".

Therefore, if there is no negative cycle, then d(u)+w(u,v)d(v),(u,v)Ed(u) + w(u, v) \ge d(v), \forall (u,v)\in E.


(b) \Leftarrow (If d(u)+w(u,v)d(v),(u,v)Ed(u) + w(u, v) \ge d(v), \forall (u,v)\in E, then there is no negative cycle)

Prove by contradiction: Assume that there exists a negative cycle

C=(u1,u2,,uk,uk+1=u1),   ω(C)<0.C' = (u_1, u_2, \ldots, u_k, u_{k+1}=u_1), \ \ \ \omega(C') < 0.

From the condition we know that (ui,ui+1)C,d(ui)+w(ui,ui+1)d(ui+1)\forall (u_i, u_{i+1}) \in C', d(u_i) + w(u_i, u_{i+1}) \ge d(u_{i+1}),

Hence

d(u1)+w(u1,u2)d(u2)d(u2)+w(u2,u3)d(u3)d(uk)+w(uk,u1)d(u1)\begin{aligned} d(u_1) + w(u_1, u_2) &\ge d(u_2) \\ d(u_2) + w(u_2, u_3) &\ge d(u_3) \\ \cdots \\ d(u_k) + w(u_k, u_1) &\ge d(u_1) \end{aligned}

sum over all the equations,

w(u1,u2)+w(u2,u3)++w(uk,u1)0w(u_1, u_2) + w(u_2, u_3) + \cdots + w(u_k, u_1) \ge 0

which is contradictory to the fact that

ω(C)=w(u1,u2)+w(u2,u3)++w(uk,u1)<0.\omega(C') = w(u_1, u_2) + w(u_2, u_3) + \cdots + w(u_k, u_1) < 0.

Therefore, if d(u)+w(u,v)d(v),(u,v)Ed(u) + w(u, v) \ge d(v), \forall (u,v)\in E, then there is no negative cycle.

(ii)

Bellman-Ford algorithm (Wiki)

function BellmanFord(list vertices, list edges, vertex source) is

// This implementation takes in a graph, represented as
// lists of vertices (represented as integers [0..n-1]) and edges,
// and fills two arrays (distance and predecessor) holding
// the shortest path from the source to each vertex

distance := list of size n
predecessor := list of size n

// Step 1: initialize graph
for each vertex v in vertices do
// Initialize the distance to all vertices to infinity
distance[v] := inf
// And having a null predecessor
predecessor[v] := null

// The distance from the source to itself is, of course, zero
distance[source] := 0

// Step 2: relax edges repeatedly
repeat |V|−1 times:
for each edge (u, v) with weight w in edges do
if distance[u] + w < distance[v] then
distance[v] := distance[u] + w
predecessor[v] := u

// Step 3: check for negative-weight cycles
for each edge (u, v) with weight w in edges do
if distance[u] + w < distance[v] then
predecessor[v] := u
// A negative cycle exists; find a vertex on the cycle
visited := list of size n initialized with false
visited[v] := true
while not visited[u] do
visited[u] := true
u := predecessor[u]
// u is a vertex in a negative cycle, find the cycle itself
ncycle := [u]
v := predecessor[u]
while v != u do
ncycle := concatenate([v], ncycle)
v := predecessor[v]
error "Graph contains a negative-weight cycle", ncycle
return distance, predecessor