Look at node a
- what could DFS do in node a
? It could go either to b
or e
. We see that it chose b
, because a->b
is a tree edge and a->e
is a forward edge (check the definition of tree/forward edge). In b
the only choice was to visit f
. In f
DFS could go either to a
, e
or g
. We can assume that it tried to visit a
(f->a
is marked as back edge, so everything is correct until now), than it visited e
and than tried to visit b
. However, we now have a problem with edge f->g
. It is marked as a cross edge, which means that DFS had already visited g
before. Otherwise, this edge would have been marked as a tree edge. So, we know that a
was not the initial node. We need to try other options. What about c
? Again, all of edges coming out of c
are marked as cross, not tree, so c
was not the initial node.
What about d
? If DFS started in d
, it could go from d
to g
and that's what happened because d->g
is marked as tree edge. There were no nodes to go from g
so it backtraced to d
and visited h
. From h
it tried to visit g
but it has already visited earlier, so h->g
is marked as cross - correct. Great, so d
was the initial node for this DFS execution. After visiting a connected component which contains d
, g
and h
, DFS could start again either from a
or c
but we already know that it has not started from c
because of those cross edges. So it started from a
and after visiting b
, f
and e
it started from c
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…