Hello guys, I was solving this problem (http://codeforces.me/contest/161/problem/D).
After trying for sometime , I read the editorial of the problem and I am not being able to understand the meaning of this line.
Can anyobdy help me with this?
I basically want to understand about logic or proof behind this.
If you fix son u of vertex v and distance x to the v, you can choose vertex with distance to the v k — x in subtree of other son of v. d[u][x — 1] is number of vertices in subtree of u with distance x — 1(becomes x when you move from u to v). d[v][k — x] is number of vertices in subtree of v with distance k — x, you subtract d[u][k — x — 1] to exclude vertices in subtree of u. Also *0.5 is because each pair is counted twice.