import typing


def find_subtour(sol: typing.Dict[typing.Tuple[int, int], float], n: int) -> typing.List[int]:
    """
    This function takes a a solution to the TSP formulation, and returns a subtour.
    :param sol: a dict, each key is a two-tuple (i,j) with i < j and sol[i,j] gives the value of the variable
                corresponding to the edge between i and j
    :param n: the number of nodes.
    :return: a subtour in the TSP formulation, starting with node 0. This returns a list of the nodes in the subtour.
    """
    start_node = 0
    prev_node = None
    current_node = start_node
    returned_to_start = False
    cycle = [start_node]
    while not returned_to_start:
        next_node = None
        for j in range(current_node + 1, n):
            if sol[current_node, j] > 0.5 and j != prev_node:
                next_node = j
        if next_node is None:
            for j in range(0, current_node):
                if sol[j, current_node] > 0.5 and j != prev_node:
                    next_node = j
        if next_node is None:
            raise RuntimeError("Failed to find subtour")
        elif next_node == start_node:
            returned_to_start = True
        else:
            cycle.append(next_node)
        prev_node = current_node
        current_node = next_node
    return cycle