Explain the code

binary-search
data-structure
dfs
greedy
tree

#1

Can someone please explain me what THIS code is doing. I know that it involves DFS on a tree/graph. It might also involve binary search. I want to know that in init() and lca() functions, why i and j are iterated only till 18?

Problem Link

Contest Link


#2

We want minimum K such that pow(2,K)>= N , here N = 100000 .

1.pow(2,16) = 65536

2.pow(2,17) = 131072

3.pow(2,18) = 262144

minimum K satisfying above condition is 17.
Any number >=17 will do.