import collections


def longest_path(current_state):
    """Find longest possible path from the current state to the final state

    Args:
        current_state: StateForGraphs
            The state at the beginning of the search; the root of the tree.

    Returns:
        The maximum number of steps that can be used to get from
        current_state to a final state, using state.possible_next_states to
        find states reachable in one step from the current state

    See Also: StateForGraphs
        to understand the required methods for the states used in the graph.
        The states must implement __hash__, __eq__, possible_next_states,
        and is_final
    """
    queue = collections.deque()
    discovered = {current_state: 0}
    queue.append(current_state)
    lengths = set()
    while queue:
        state = queue.popleft()
        num_steps = discovered[state]
        new_states = state.possible_next_states()
        for new_state in new_states:
            if new_state.is_final():
                lengths.add(num_steps + 1)
            elif new_state not in discovered:
                queue.append(new_state)
            discovered[new_state] = num_steps + 1
    return max(lengths)