def get_common_ancestor(node1, node2):
    if (node1 == node2):
        return node1
    node1_parents = list()
    parent1 = node1
    while (parent1 != None):
        node1_parents.append(parent1)
        parent1 = parent1.parent
    node2_parents = list()
    parent2 = node2
    while (parent2 != None):
        node2_parents.append(parent2)
        parent2 = parent2.parent
    common_ancestor = None
    for p1 in node1_parents:
        for p2 in node2_parents:
            if (p1 == p2):
                common_ancestor = p1
                break
        if (common_ancestor != None):
            break
    return common_ancestor
def get_common_ancestor(node1, node2):
    if (node1 == node2):
        return node1
    node1_parents = list()
    parent1 = node1
    while (parent1 != None):
        node1_parents.append(parent1)
        parent1 = parent1.parent
    node2_parents = list()
    parent2 = node2
    while (parent2 != None):
        node2_parents.append(parent2)
        parent2 = parent2.parent
    common_ancestor = None
    for p1 in node1_parents:
        for p2 in node2_parents:
            if (p1 == p2):
                common_ancestor = p1
                break
        if (common_ancestor != None):
            break
    return common_ancestor