Trimble MAPS interview question

Question on Graph (leetcode medium)