京都大学 情報学研究科 数理工学専攻 2019年8月実施 アルゴリズム基礎
Author
祭音Myyura
Description
日本語版
(1) 任意の点
(2)
(3) 異なる二点
English Version
Let
(1) Let
(2) Show how to test whether
(3) Let
Kai
Let
For a path
Let
(1)
We first prove that for any common vertex
Assume that
Then, let
which is odd.
(2)
The idea algorithm can be established from the following statement and (1):
- A simple undirected graph
is bipartite iff it contains no odd length cycle.
(
Assume that there exists a cycle
W.l.o.g we assume that
Therefore, if
(
Assume that there exists two vertices
With similar statement in (1), let
Therefore, if
Algorithm
Let
algorithm IsBipartite(G(V, E), s):
Q <- create an empty queue
color[s] <- RED
Q.enqueue(s)
while Q is not empty:
n1 <- Q.dequeue()
for each n2 in n1.Adj():
if color[n2] = null:
if color[n1] = RED:
color[n2] = BLUE
else:
color[n2] = RED
Q.enqueue(n2)
else:
if color[n2] = color[n1]:
return 'Graph is not Bipartite'
return 'Graph is Bipartite'
(3)
- Use BFS to find a shortest
-path in . - Let
denote an edge of . Use BFS to find a shortest -path in . - If length of the two paths we found are same, then
have two or more shortest paths between and . - If length of the two paths we found are not same, then
has only one shortest path between and .