WA in SPOJ question Longest Path In a Tee

Revision en1, by vee_sharp, 2015-12-24 21:38:34

Hello I am trying to solve the question :http://www.spoj.com/problems/PT07Z/ in SPOJ. I have used bfs to find the leaf node and then used bfs again to find the maximum path. I know there are other methods to solve this like simply finding the diameter of a tree in O(n) time. But I am trying this approach and I don't know what is causing the error. Here is a link to my solution http://ideone.com/QSJzDf.

Tags spoj, c++, bfs

History

 
 
 
 
Revisions
 
 
  Rev. Lang. By When Δ Comment
en3 English vee_sharp 2015-12-24 21:46:06 106
en2 English vee_sharp 2015-12-24 21:42:09 13 Tiny change: 'a tree in O(n) time. But I am' -> 'a tree in one loop. But I am'
en1 English vee_sharp 2015-12-24 21:38:34 447 Initial revision (published)