Atcoder Beginner Contest 201 E: Xor Distances (Tree/ LCA)

Atcoder Beginner Contest 201 E: Xor Distances (Tree/ LCA)

Atcoder Graph/ Tree Algorithms for Competitive Programming: I have discussed a useful idea to solve other Tree problems. Problem Link: https://atcoder.jp/contests/abc201/ta... Submission Link: https://atcoder.jp/contests/abc201/su... Notes: 1) This problem was a typical problem of the general form : compute the sum of dist(i,j) for all pairs (i,j) where dist(i,j) is a function related to the weights of the edges in the path from i to j. 2) What made the problem easy was the dist(i,j) was invertible as the inverse of xor is xor itself. This facilitated the easy solution idea that followed. 3) Also be sure to follow the techniques used to solve the above problem in other tree problems – Root the tree at a node and always consider that the path from i to j is the path from i to lca(i,j) + the path from lca(i,j) to j. If you have any doubts on the solution, please feel to post them in the comments below. If you liked this video, please give it a "thumbs up". Also, consider subscribing to my channel if you would like to see similar content.