Пожалуйста, подпишитесь на официальный канал Codeforces в Telegram по ссылке https://t.me/codeforces_official. ×

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

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

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
  • Проголосовать: не нравится

»
9 лет назад, # |
  Проголосовать: нравится +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

  • »
    »
    9 лет назад, # ^ |
      Проголосовать: нравится +3 Проголосовать: не нравится

    oow, thank you so much for advice.

    After looking for the diameter of a tree, this problem look so easy xD

    Thanks very much :D

»
9 лет назад, # |
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!

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

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