Add a unit test that specifically covers graphs with cycles or multiple paths to ensure that the traversal does not result in infinite loops or redundant visits. For example, a cycle like A -> B -> A or a diamond shape like A -> B -> D and A -> C -> D.
Add a unit test that specifically covers graphs with cycles or multiple paths to ensure that the traversal does not result in infinite loops or redundant visits. For example, a cycle like A -> B -> A or a diamond shape like A -> B -> D and A -> C -> D.