29
Only one connected component is checked.
The loop
for
each
(v,w)∈edges(G)
do
should exclude the neighbour of v from which you just came, so as to prevent a single edge
w-v
from being classified as a cycle.