def reconstruct_path(state, parents: dict) -> list:
    """Reconstructs a path to a state.

    Args:
        state: The final state in the path.
        parents: A dict of the form [child, parent].

    Returns:
        A list representing the path from the origin to the given state.
    """
    path = [state]
    while state in parents:
        state = parents[state]
        path.append(state)
    path.reverse()
    return path