def is_option(current, neighbor):
    """
    Returns whether the neighbor is a valid option to be set as the child of current.
    """
    # Remaining segments that the neighbor would have as the child of current
    neighbor_remaining_segments = (
        current.remaining_segments - neighbor.is_on_different_segment(current)
    )
    return (
        neighbor.is_open()
        and neighbor_remaining_segments > 0
        # Logically equivalent to "neighbor is sink implies one remaining segment"
        and (not neighbor.is_sink() or neighbor_remaining_segments == 1)
    )