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

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

I try it using a BFS. Starting in a node with degree 1, setting the node as visited and its neighbors, adding in the queue the neighbors of neighbors of node. But, i was received only wrong answer with this strategy :(

Link for the problem: http://www.spoj.com/problems/IMPER/

sorry for my bad english.

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

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

Your approach will lead to WA, consider the following test case:

10

1 2 3 4 2 6 7 8 9

-1

What is the right answer?

To solve this problem you need to learn what is and how to calculate the diameter of a tree. I won't link any tutorial, since I don't know about any particularly good, but googling it should be enough.

This is the code I got Accepted with: Don't click me

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

I got Accepted in 2 OJ and there is one thing I can't understand:

Why does this case return 2 instead of 3?

7

1 2 1 4 1 6

Thanks!

»
10 лет назад, скрыть # |
Rev. 2  
Проголосовать: нравится +4 Проголосовать: не нравится

One of the tags of this post is "need help" XD .