From Jeff Erickson's lecture notes on graph algorithms, there is an exercise to check whether a walk between given vertexes s
and t
can be divisible by 3 in a directed graph.
What I thought is to use breadth-first search on the graph to get all paths from s
to t
. If the simple paths don't have lengths divisible by 3, run the algorithm again to check if there is a cycle between s
and t
where the length of cycle is not divisible by 3. However, I feel the method is really inefficient.
It would be great if you have any good suggestion about this question.