Preface

这是一篇英文题解。This is an English solution.

Solution

Consider the necessary and sufficient condition for P(T)=vP(T)=v:

  • Edge (v,n)(v,n) exists in TT;
  • Let nn be the root of TT. Then, n1n-1 is in the subtree of vv.

This is because every vertex u(u<n1,u is not an ancestor of n1)u(u< n-1,u\ \text{is not an ancestor of}\ n-1) is removed before n1n-1.

If n1n-1 and nn are in the same tree, when vv is both an ancestor of n1n-1 (including vv itself) and a child of nn, all nk2i=1ksin^{k-2}\prod\limits^k_{i=1}s_i ways are valid. Otherwise, the answer is 00.

If n1n-1 and nn are in different connected components, calculate answer for each node vv. When vv and nn are not connected by an edge, just add the edge (v,n)(v,n). After that, we could only consider the second constraint. Here’s the critical part: now the answer is svSnk2i=1ksi\frac{s_v}{S}n^{k-2}\prod\limits_{i=1}^ks_i, where svs_v is the size of the subtree of vv, and SS is the size of the whole tree containing nn, since all valid edge additions are equivalent by symmetry (that is, the probability of randomly choosing a way to add the edges, in which the subtree containing n1n-1 is connected to the side of vv is svS\frac{s_v}{S}). If we added the edge (v,n)(v,n) manually, the formula should be applied to the new graph, that is svsv+Snk3(sv+S)icv,cnsi\frac{s_v}{s_v+S}n^{k-3}(s_v+S)\prod\limits_{i≠c_v,c_n}s_i, where cxc_x is the connected component containing xx.