跳到主要内容

京都大学 情報学研究科 数理工学専攻 2021年8月実施 アルゴリズム基礎

Author

祭音Myyura

Description

日本語版

G=(V,E)G=(V,E) を点集合 VV ,枝集合 EE から成る単純有向グラフとする. R(u;G)R(u; G)GG において点 uu から有向路で到達できる点の集合と定め,dist(u,v,;G)\text{dist}(u, v,; G) を点 uu から点 vv へ至る GG の有向路の最短の長さとする. vR(u;G)v \notin R(u; G) のときは dist(u,v,;G)V\text{dist}(u, v,; G) \triangleq |V| と定める. 有向グラフ GG から有向枝 eEe \in E を削除した有向グラフを GeG - e と記す. s,ts, tVV の二点とする. GG は隣接リストにより貯えられているとする.以下の問いに答えよ.

(i) tR(s;G)t \in R(s; G) と仮定する. 点 ss から点 tt へ至る有向路で最短のものを求める O(V+E)O(|V| + |E|) 時間アルゴリズムを与えよ.

(ii) dist(s,t;Ge)>dist(s,t;G)\text{dist}(s, t; G - e) > \text{dist}(s, t; G) を満たす有向枝 eEe \in E が存在するかどうかを判定する O(V+E)O(|V| + |E|) 時間アルゴリズムを与えよ.

(iii) dist(s,t;G)=dist(t,s;G)=3<dist(s,t;Ge)=dist(t,s;Ge)\text{dist}(s, t; G) = \text{dist}(t, s; G) = 3 < \text{dist}(s, t; G - e) = \text{dist}(t, s; G - e) である二点 s,tVs, t \in V 有向枝 eEe \in E をもつ有向グラフ G=(V,E)G=(V, E) の例を作成せよ.

English Version

Let G=(V,E)G=(V,E) be a simple directed graph with a vertex set VV and an edge set EE. Let R(u;G)R(u; G) denote the set of vertices reachable from a vertex uu by a directed path in GG and dist(u,v;G)\text{dist}(u, v; G) denote the shortest length of a path from a vertex uu to a vertex vv in GG, where we set dist(u,v,;G)V\text{dist}(u, v,; G) \triangleq |V| if vR(u;G)v \notin R(u; G). Let GeG − e denote the directed graph obtained from GG by removing a directed edge eEe \in E. Let ss and tt be two vertices in VV. Assume that GG is stored in adjacency lists. Answer the following questions.

(i) Assume that tR(s;G)t \in R(s; G). Give an O(V+E)O(|V | + |E|)-time algorithm that computes a directed path with the shortest length from ss to tt.

(ii) Give an O(V+E)O(|V |+|E|)-time algorithm that tests whether there exists a directed edge eEe \in E such that dist(s,t;Ge)>dist(s,t;G)\text{dist}(s, t; G − e) > \text{dist}(s, t; G).

(iii) Construct an example of a directed graph G=(V,E)G = (V, E) that contains two vertices s,tVs, t \in V and a directed edge eEe ∈ E such that dist(s,t;G)=dist(t,s;G)=3<dist(s,t;Ge)=dist(t,s;Ge)\text{dist}(s, t; G) = \text{dist}(t, s; G) = 3 < \text{dist}(s, t; G − e) = \text{dist}(t, s; G − e).

Kai

(i)

We use BFS to compute shortest paths in an unweighted graph.

BFS(s, G=(V, E)):
for each v in V set dist(s, v; G) = |V|
for each v in V set visited(v) = 0
for each v in V set pred(v) = -1
dist(s) = 0
visited(s) = 1
set Q to be the empty queue
Q.enqueue(s)
while Q is not empty do:
u = Q.dequeue()
for each neighbor v of u do:
if visited(v) = 0 then:
visited(v) = 1
Q.enqueue(v)
dist(s, v; G) = dist(s, u; G) + 1
pred(v) = u

The time complexity of BFS is O(V+E)O(|V| + |E|) when GG is stored in adjacency lists.

(ii)

The idea is to find "bridges" in the graph that consists of all the edges of shortest paths from ss to tt.

Let Es,tE_{s,t} denote the edge set of all the edges of shortest paths from ss to tt. To find Es,tE_{s,t}, we do the following steps:

  • use BFS to compute dist(s,u;G),uV\text{dist}(s, u; G), \forall u \in V
  • let GTG^T denote the reversed graph of GG (i.e. the same vertex set but all of the edges reversed), use BFS to compute dist(t,u;GT),uV\text{dist}(t, u; G^T), \forall u \in V
  • Es,t={(u,v)dist(s,u;G)+dist(t,v;GT)=dist(s,t;G)}E_{s,t} = \{(u, v) \mid \text{dist}(s, u; G) + \text{dist}(t, v; G^T) = \text{dist}(s, t; G)\}

Obviously, it takes O(V+E)O(|V| + |E|)-time to find the edge set Es,tE_{s,t}.

Then, we can use Tarjan' algorithm to find bridges

GetArticulationPoints(i, d)
visited[i] := true
depth[i] := d
low[i] := d
childCount := 0
isArticulation := false

for each ni in adj[i] do
if not visited[ni] then
parent[ni] := i
GetArticulationPoints(ni, d + 1)
childCount := childCount + 1
if low[ni] ≥ depth[i] then
isArticulation := true
low[i] := Min (low[i], low[ni])
else if ni ≠ parent[i] then
low[i] := Min (low[i], depth[ni])
if (parent[i] ≠ null and isArticulation) or (parent[i] = null and childCount > 1) then
Output i as articulation point

The time complexity of Tarjan' algorithm is also O(V+E)O(|V| + |E|)

If there exists a articulation point aa in graph Gs,t=(V(Es,t),Es,t)G_{s,t} = (V(E_{s,t}), E_{s,t}), i.e., there exists a bridge ee (adjacent to aa) in Es,tE_{s,t}, then the removal of ee disconnects Gs,tG_{s,t}, which implies that there is no path of length dist(s,t;G)\text{dist}(s, t; G) in GeG - e, i.e. dist(s,t;Ge)>dist(s,t;G)\text{dist}(s, t; G − e) > \text{dist}(s, t; G)

(iii)

V={s,t,v1,v2,v3,v4}E={(s,v2),(t,v2),(v2,v1),(v1,s),(v1,t),(v2,v3),(v3,v4),(v4,s),(v4,t)}e=(v2,v1)G=(V,E)\begin{aligned} V &= \{s, t, v_1, v_2, v_3, v_4\} \\ E &= \{(s, v_2), (t, v_2), (v_2, v_1), (v_1, s), (v_1, t), (v_2, v_3), (v_3, v_4), (v_4, s), (v_4, t)\} \\ e &= (v_2, v_1) \\ G &= (V, E) \end{aligned}