find the nearest common ancestor of two nodes