Longest path in the tree

Правка en1, от iamdumb, 2015-06-27 22:41:14

Hello everyone,I was trying to do this question from spoj.First I had no idea how to do this question so,I googled and algorithms that came out was this

Algorithm: Run BFS from any node to find the farthest leaf node. Label that node T. Run another BFS to find the farthest node from T. The path you found in step 2 is the longest path in the tree.

But my problem is that it is becoming really very difficult to implement what is asked.Can anybody show me the code what is asked.Preferably in C++ and using dfs.Thanks.

Теги longest path, c++

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский iamdumb 2015-06-27 22:41:53 39
en1 Английский iamdumb 2015-06-27 22:41:14 556 Initial revision (published)