跳到主要内容

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

题目描述

G=(V,E)G=(V,E) 为简单强连通有向图,V=n|V|=nE=m|E|=m。网络 N=[G,w]N=[G,w] 给每条边 ee 赋实权 w(e)w(e)。对依次经过 v1,,vkv_1,\ldots,v_k 的有向路 P=(v1,,vk)P=(v_1,\ldots,v_k),定义

μ(P)=k1,ω(P)=i=1k1w(vi,vi+1).\mu(P)=k-1,\qquad \omega(P)=\sum_{i=1}^{k-1}w(v_i,v_{i+1}).

给定 sVs\in V。对每个 vVv\in V,令 d(v)d(v) 为所有从 ssvv 且边数不超过 n1n-1 的路的最小权重和;令 d(v)d^*(v) 为从 ssvv 的所有简单路的最小权重和。若回路 CC 满足 ω(C)<0\omega(C)<0,称其为负环。回答:

  1. 证明 NN 不含负环,当且仅当

    d(u)+w(u,v)d(v),(u,v)E.d(u)+w(u,v)\ge d(v),\qquad\forall (u,v)\in E.
  2. 给出一个 O(mn)O(mn) 时间算法:判定 NN 是否存在负环;若不存在,则输出所有 vVv\in Vd(v)d^*(v)

Kai

(i)

(\Rightarrow) Suppose that NN has no negative cycle. Assume for contradiction that an arc (u,v)(u',v') satisfies

d(u)+w(u,v)<d(v).d(u')+w(u',v')<d(v').

Let PuP_{u'} be a path from ss to uu' with at most n1n-1 arcs and weight d(u)d(u'), and append (u,v)(u',v') to obtain a walk PuvP_{u'v'}. If PuvP_{u'v'} had at most n1n-1 arcs, then the definition of d(v)d(v') would give

d(v)ω(Puv)=d(u)+w(u,v),d(v')\le \omega(P_{u'v'})=d(u')+w(u',v'),

which is a contradiction. Hence PuvP_{u'v'} has a repeated vertex. Delete its repeated-vertex subcycles one at a time. Every deleted cycle has nonnegative weight, so the resulting simple ss-vv' path SS satisfies

μ(S)n1,ω(S)d(u)+w(u,v)<d(v),\mu(S)\le n-1,\qquad \omega(S)\le d(u')+w(u',v')<d(v'),

again contradicting the definition of d(v)d(v'). Therefore

d(u)+w(u,v)d(v),(u,v)E.d(u)+w(u,v)\ge d(v),\qquad (u,v)\in E.

(\Leftarrow) Conversely, suppose these inequalities hold for every arc. If

C=(u1,u2,,uk,uk+1=u1)C=(u_1,u_2,\ldots,u_k,u_{k+1}=u_1)

is a directed cycle, then

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),\\ &\ \vdots\\ d(u_k)+w(u_k,u_1)&\ge d(u_1). \end{aligned}

Summing and cancelling the d(ui)d(u_i) terms gives

ω(C)=i=1kw(ui,ui+1)0.\omega(C)=\sum_{i=1}^{k}w(u_i,u_{i+1})\ge0.

Thus no negative cycle exists.

(ii)

BellmanFord(V, E, s):
for each vertex v in V:
D[v] = infinity
predecessor[v] = null
D[s] = 0

repeat n-1 times:
Dnew = D
predecessor_new = predecessor
for each arc (u,v) with weight w(u,v):
if D[u] + w(u,v) < Dnew[v]:
Dnew[v] = D[u] + w(u,v)
predecessor_new[v] = u
D = Dnew
predecessor = predecessor_new

for each arc (u,v) with weight w(u,v):
if D[u] + w(u,v) < D[v]:
report "negative cycle"

return D, predecessor

After the kkth pass, D[v]D[v] is the minimum weight of an ss-vv path using at most kk arcs; this follows by induction on kk. Hence after n1n-1 passes, D[v]=d(v)D[v]=d(v).

The final scan finds a relaxable arc exactly when the inequalities in (i) fail, which by (i) is equivalent to the existence of a negative cycle. If no negative cycle exists, deleting repeated-vertex cycles from any path never increases its weight. Therefore a minimum path can be chosen simple, and

D[v]=d(v)=d(v),vV.D[v]=d(v)=d^*(v),\qquad v\in V.

Each of the n1n-1 passes scans all mm arcs, and the final scan takes O(m)O(m) time. Thus the total running time is O(mn)O(mn).

Alternative: in-place Bellman--Ford with cycle reconstruction

The standard in-place relaxation also satisfies the required bound and can return a negative cycle when one exists.

BellmanFordInPlace(V, E, s):
for each vertex v in V:
D[v] = infinity
predecessor[v] = null
D[s] = 0

repeat n-1 times:
for each arc (u,v) with weight w(u,v):
if D[u] != infinity and D[u] + w(u,v) < D[v]:
D[v] = D[u] + w(u,v)
predecessor[v] = u

x = null
for each arc (u,v) with weight w(u,v):
if D[u] != infinity and D[u] + w(u,v) < D[v]:
D[v] = D[u] + w(u,v)
predecessor[v] = u
x = v

if x = null:
return D, predecessor

repeat n times:
x = predecessor[x]
cycle = [x]
v = predecessor[x]
while v != x:
cycle.append(v)
v = predecessor[v]
cycle.append(x)
reverse(cycle)
report "negative cycle", cycle

All vertices are reachable from ss because GG is strongly connected. Thus a relaxation in the extra pass occurs if and only if a negative cycle exists. Following nn predecessor edges from a relaxed vertex reaches such a cycle, and the subsequent loop reconstructs it. The algorithm scans all mm arcs in nn passes, so its running time is O(mn)O(mn).