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

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

Hello.

Today I was looking the problems from AtCoder Grand Contest 18. In problem D you were asked to find the length of the largest Hamilton Path in a complete graph with edges between two vertices equal to the length between these two vertices in a given tree. In the problem you need to find just the length of the path and the solution which I found to the problem can do this. But unfortunately it can just give the length of the path, not the order in which we visit the vertices (my solution is similar to the one in the editorial). So is there a solution with which the order we visit the vertices is easily recoverable (well actually even if it's not easy I would appreciate if you share your idea) and also is still fast enough (something like or faster).

Thanks in advance :)

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

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

Auto comment: topic has been updated by radoslav11 (previous revision, new revision, compare).

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

after rooting at the centroid , the order of visiting nodes pretty much doesn't matter as long as two consecutive nodes are from different subtrees of the root , so at each step , choose a node from largest subtree which is different from the last node chosen.

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

    Thanks. I also had that idea but I don't know why I thought that after we have chosen some nodes it would be possible that some paths won't go through the centroid but obviously if we choose the largest subtree that will never happen. Thanks again.

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