spoj the benefactor

i dont know why i am getting wrong answer can any one please help me,thanks in advance
link text

use two bfs,start from 1 and by using bfs find the node with max distace ,making this node as starting point find the node with maz distace
Algorithm:
start:=bfs(G,1);
res:=bfs(G,start);