Intersecting Paths

find lowest common ancestor ( common grand parent ( or parent) having lowest height)
then use prefix sum over trees to fetch answer of query by dividing it into two queries

i=LCA(a,b)
query(a,b) = find(i,a) + find(i,b)
use pre computed prefix sum in find(i,a) and find(i,b)
https://www.codechef.com/viewsolution/24716158

4 Likes