|
|
back to boardnt No, the idea is to make the longest road in the tree and choose the middle nodes as the answer. It may be 1 or 2 numbers so... That is possible in O(N) :) Yes you are right... i'm trying to solve it same way. But It's a problem how to find the longest chane in the tree. Edited by author 22.06.2005 22:48 It can be solved using just one DFS. But i think ans may contain more than two numbers According to Jordan's Theorem (Introduction to Graph Theory - Douglas B. West - Second Edition - Page 70), the center of a tree is a vertex or two and you can find them this way: Each time remove all the leaves (so the eccentricity of all the vertices will be decreased by one) and repeat this step until only one or two vertices remain |
|
|