def find_root(nodes):
    """Find the root of the tree

    :nodes: dict of Node objects
    :return: root Node"""

    # pick a node and follow its parent up until we got one without a parent
    root = next(iter(nodes.values()))

    while root.parent:
        root = root.parent

    return root