We consider dynamic programming. Let $$$\mathrm{dp}_{i,j,0/1}$$$ represent the expected number of steps when currently at node $$$i$$$ with $$$j$$$ coins and about to take an even/odd step. To simplify the formulation: - Define $$$\mathrm{sc}_i := \text{number of children of } i, p_i := \text{parent of } i$$$. - The initial condition is $$$\mathrm{dp}_{1,j,0/1} = 1$$$.
Odd steps are straightforward:
$$$ \mathrm{dp}_{i,j,1} = \mathrm{dp}_{p_i,j,0} + 1. $$$From the problem description:
$$$ \mathrm{dp}_{i,j,0} = 1 + \begin{cases} \mathrm{dp}_{p_i,j-1,1}, & \text{(to pay)} \\ \dfrac{\mathrm{dp}_{p_i,j,1} + \sum_{u \text{ is a child of } i} \mathrm{dp}_{u,j,1}}{\mathrm{sc}_i + 1}, & \text{(not to pay)} \end{cases}. $$$The "not to pay" case involves both the parent and children, making it more complex. However, observe that:
$$$ \forall u \text{ is a child of } i : \mathrm{dp}_{u,j,1} = \mathrm{dp}_{p_u,j,0} + 1 = \mathrm{dp}_{i,j,0} + 1. $$$This implies that for the "not to pay" case:
$$$ \begin{aligned} \mathrm{dp}_{i,j,0} &= 1 + \dfrac{\mathrm{dp}_{p_i,j,1} + \sum (\mathrm{dp}_{i,j,0} + 1)}{\mathrm{sc}_i + 1} \\ &= \dfrac{\mathrm{dp}_{p_i,j,1} + \mathrm{sc}_i \mathrm{dp}_{i,j,0} + 2 \mathrm{sc}_i + 1}{\mathrm{sc}_i + 1}. \end{aligned} $$$Reorganizing:
$$$ (\mathrm{sc}_i + 1) \mathrm{dp}_{i,j,0} = \mathrm{dp}_{p_i,j,1} + \mathrm{sc}_i \mathrm{dp}_{i,j,0} + 2 \mathrm{sc}_i + 1, $$$ $$$ \mathrm{dp}_{i,j,0} = \mathrm{dp}_{p_i,j,1} + 2 \mathrm{sc}_i + 1. $$$Thus:
$$$ \mathrm{dp}_{i,j,0} = \min \{\mathrm{dp}_{p_i,j-1,1}, \mathrm{dp}_{p_i,j,1} + 2 \mathrm{sc}_i\} + 1. $$$