ACM ICPC Naga 2014 – Problem F: Diameter of a Tree
Dr. Manalastas, the author of this problem, is my friend in Facebook. Since my second year in college, I have seen him as someone who I should have a picture with. Our coach before spoke too highly of him that every time I see him on campus (he is also a professor at Ateneo de Davao’s graduate school), I feel that there is a light that surrounds him, an aura of a genius. I quickly moved on with my “man crush” feelings for him when I knew of Dr. Steven Halim. I even have a picture of us two! No homo, though.
I opened with that paragraph since I saw a Facebook post of Dr. Manalastas about this next problem. He revealed that the solution to this problem is by using Floyd-Warshall All-Pairs Shortest Path (APSP) algorithm. This algorithm is very slow and it has an O(n^3) runtime! This should only be used when you actually need shortest paths of multiple pairs, if not all of them. As you will read along the problem statement, you would realize that there is a better approach to this problem, which is by using the Breadth-First Search algorithm. But no matter what his solution here is, he is still much smarter than me.
Edit: In the Facebook post of Dr. Manalastas, he also mentioned a student who also has the same solution as mine.
(All the problems in the contest are compiled in a PDF format found here)