Whats the formulae for this ques?

I’m getting (d*pow(2,d-1))/(pow(2,d)-1)*(pow(2,d+1)-1) , in the form of p/q.

Whats the formulae for this ques?

I’m getting (d*pow(2,d-1))/(pow(2,d)-1)*(pow(2,d+1)-1) , in the form of p/q.

https://www.codechef.com/viewsolution/30811669

p = first count the valid pair, an edge can only inserted in b/w the vertices iff one node is

a part other node’s subtree

to keep the cycle black and white even numbers of nodes are required

just iterate over the d, and count all the valid pair

count total node n = pow(2, d+1) - 1 // modulo operation

**q = nc2 * 2** extra 2 factor for option (of having black and white)

p/q , use fermate theorem

ans = p * power(q, 1000000007 - 2)