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

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

Hello codeforces!

I recently got interested in the LCA problem and read a lot about it. I learned three methods for computing LCA queries:

  • Using Sparse Table (But i didn't like that approach since the 2-d array gives me outofmemory exception when number of nodes is 10^5 )

  • Transforming my rooted tree into an array and apply segment trees on it. This method works well for me but takes much too long to code.

  • Using Union-Find data structure.

Which approach do you use and why? Thanks!

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

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

I use ST. I think it's the most convinient one.

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

If the time and memory limits allow it, I would go for binary lifting method. Otherwise, I will most likely code heavy-light decomposition which gives O(N) preprocessing, O(N) memory and O(logN) per query :)

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

I use sparse table (parent[lgN][N]) as it's easy to code and doesn't require any additional knowledge (segment trees).
BTW, if N=100000, 4*17*100000 = 6.8 MB. Where is your MLE?