parents to store child-parent relationships.regions, map each child (from the second element onwards) to its parent (the first element).ancestryHistory to store the ancestors of region1.region1 to ancestryHistory and update region1 to its parent until it has no parent.region2 is in ancestryHistory. If not, update region2 to its parent and repeat until region2 is found in ancestryHistory.region2 as the smallest common region.