• Search the graph for a directed cycle and return its path.

    Parameters

    Returns null | readonly string[]

    Cycle path as A1 keys, or null when the graph is acyclic.

    Implements the classic three-colour DFS: visited records nodes that have ever been entered, onStack (paired with the explicit stack array) tracks the current recursion path, and a back-edge to a node currently on the stack signals a cycle. The returned path starts and ends at the same node so callers can render it as A1 → B2 → A1.