京都大学 情報学研究科 数理工学専攻 2023年8月実施 グラフ理論
Author
祭音Myyura
Description
日本語版
を節点集合 、 枝集合 から成る単純強連結有向グラフとし、 に属する節点の個数を 、に属する枝の本数を とする。 の各枝 に実数値重み を与えて得られるネッタワークを とする。 節点 から節点 への有向枝は と書き、その枝重みは とも書く。 節点 をこの順に訪ねる路 について、枝の本数を 、枝重みの和を と書く。
節点 が与えられたものとする。各節点 について、 から への路 で を満たすものにおける のうち、最小値を と定める。 また から への単純路 における のうち、最小値を と定める。 を満たす閉路 を負閉路と呼ぶ。以下の問いに答えよ。
(i) に負閉路が存在しないとき、かつその時に限り、
が成り立つことを示せ。
(ii) に負閉路が存在するかどうかを判定し、もし存在しない場合には全ての に対して を出力する、 時間のアルゴリズムを与えよ。
English Version
Let denote a simple, strongly connected digraph with a vertex set and an edge set , let denote the number of vertices in , and let denote the number of edges in . Let denote a network obtained from by assigning a real value to each edge as its weight. A directed edge from a vertex to a vertex is denoted by and its weight is written as . When a path visits vertices in this order, let denote the number of edges in and let denote the summation of weights of edges in
Suppose that a vertex is given. For each vertex , we define to be the minimum of among all paths from to such that . We define to be the minimum of among all simple paths from to . A cycle is called a negative cycle if . Answer the following questions.
(i) Prove that there is no negative cycle in if and only if
(ii) Show an -time algorithm that determines whether or not there exists a negative cycle in and that outputs for all if no negative cycle exists.
题目描述
设 为简单强连通有向图,、。网络 给每条边 赋实权 。对依次经过 的有向路 ,定义
给定 。对每个 ,令 为所有从 到 且边数不超过 的路的最小权重和;令 为从 到 的所有简单路的最小权重和。若回路 满足 ,称其为负环。回答:
-
证明 不含负环,当且仅当
-
给出一个 时间算法:判定 是否存在负环;若不存在,则输出所有 的 。
Kai
(i)
() Suppose that has no negative cycle. Assume for contradiction that an arc satisfies
Let be a path from to with at most arcs and weight , and append to obtain a walk . If had at most arcs, then the definition of would give
which is a contradiction. Hence has a repeated vertex. Delete its repeated-vertex subcycles one at a time. Every deleted cycle has nonnegative weight, so the resulting simple - path satisfies
again contradicting the definition of . Therefore
() Conversely, suppose these inequalities hold for every arc. If
is a directed cycle, then
Summing and cancelling the terms gives
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 th pass, is the minimum weight of an - path using at most arcs; this follows by induction on . Hence after passes, .
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
Each of the passes scans all arcs, and the final scan takes time. Thus the total running time is .
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 because is strongly connected. Thus a relaxation in the extra pass occurs if and only if a negative cycle exists. Following predecessor edges from a relaxed vertex reaches such a cycle, and the subsequent loop reconstructs it. The algorithm scans all arcs in passes, so its running time is .