def getMRCA(tree, id1, id2):
    """Return the MRCA of two nodes in an NXTree."""
    candidates1 = set([id1])
    curNode = id1
    while tree.hasParent(curNode):
        curNode = tree.getParent(curNode)
        candidates1.add(curNode)
    curNode = id2
    if curNode in candidates1:
        return curNode
    while tree.hasParent(curNode):
        curNode = tree.getParent(curNode)
        if curNode in candidates1:
            return curNode
    raise RuntimeError("No MRCA found for nodes %d and %d" % (id1, id2))