Блог пользователя Magikarp

Автор Magikarp, 10 лет назад, По-английски

Hi!

I am trying to solve this problem: http://www.spoj.com/problems/PT07Z/ . I am trying to find the diameter of the tree by using double BFS but I am getting TLE. Here is my code:

http://ideone.com/vC9vsd

Thank you.

  • Проголосовать: нравится
  • 0
  • Проголосовать: не нравится

»
10 лет назад, # |
  Проголосовать: нравится 0 Проголосовать: не нравится

You don't need to use a map neither a BitSet, that could be taking a lot of time, instead make a simple array for represent the tree and a boolean array to mark visited nodes.

I think a DFS would be a better approach.