京都大学 情報学研究科 数理工学専攻 2025年8月実施 グラフ理論
Author
祭音Myyura
Description
頂点集合
(1)
(2) 以下の (a),(b),(c) の各条件について,
- (a) どの2頂点
についても, と の高々一方が成り立つ. - (b) どの2頂点
についても, と の両方が成り立つ. - (c) どの2頂点
についても, と の少なくとも一方 が成り立つ.
Kai
(i)
Use depth-first search with three colors.
Each vertex is colored as follows:
- white: not yet discovered;
- gray: discovered but not finished, so it is currently in the DFS recursion stack;
- black: finished.
The algorithm is as follows.
for each vertex v in V:
color[v] = white
for each vertex v in V:
if color[v] = white:
DFS(v)
DFS(u):
color[u] = gray
for each arc u -> v:
if color[v] = gray:
report "there is a directed cycle"
if color[v] = white:
DFS(v)
color[u] = black
The running time is
To prove correctness, first suppose that DFS finds an arc
Conversely, suppose that
Let
(ii)
(a)
The condition is equivalent to the following
The remaining directed graph has no directed cycle.
Indeed, if there is a directed cycle containing at least two distinct vertices, then any two vertices on the cycle are mutually reachable, contradicting the condition. Conversely, if two distinct vertices
Therefore, we may apply the algorithm from part (i). If the remaining graph is acyclic, condition (a) holds; otherwise it does not. The running time is
(b)
(c)
Let the strongly connected components of
Contract each strongly connected component into one vertex. The resulting graph is called the condensation graph of
Algorithm:
-
Compute the strongly connected components of
. -
Construct the condensation graph
. -
Compute a topological ordering of
: -
For each
, check whether contains the arc -
If all such arcs exist, output true. Otherwise, output false.
To implement step 4 in linear time, mark all arcs of
Now we prove correctness.
First suppose that the algorithm outputs true. Then for every consecutive pair in the topological ordering, there is an arc
Hence for any
Therefore every pair of components is comparable by reachability. Since vertices inside the same strongly connected component are mutually reachable, for any two vertices
Conversely, suppose that
of
Thus the algorithm will output true.
The running time is