Solution not getting accepted

problem link:
https://practice.geeksforgeeks.org/problems/save-winterfell/0

code link:

plz tell why this is showing wrong output(runtime error)…
is the logic of my code for this problem correct…???

Plz reply to this doubt at the earliest

First use DFS using any vertice to calculate longest distance ,then again do DFS for vertex having longest distance in first iteration. here is my solution submit and dry run this https://ide.codingblocks.com/s/245942