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

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

The following POI problem: main.edu.pl/en/archive/oi/21/hot, which asks one to find the number of vertices of a tree equidistant from one vertex, has a fairly simple O(n^2) solution, which is sufficient to get full points. However, when looking at the solution, there appeared to be a O(n log n) solution that used what appeared to be centroid decomposition, though it was hard to tell, since the solution was in Polish and google translate doesn't do that good of a job. What is a solution to this problem in O(n log n) that uses centroid decomposition, and are there any other solutions that get O(n log n) or better?

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

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

You do the exact same thing that you do in the N^2 solution, except you do it on the centroid decomposition tree instead.

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

    How would such a solution work though, because the O(n^2) solution I had in mind was to compute for every vertex the number of triples equidistant to that vertex, which I did by counting the number of vertices at a particular depth for each vertex, and then using some tricks with symmetric sums to get sums of products of triples of those. What is the solution that generalizes to allow for centroid decomposition?