We need to simplify the input. Let's define a graph on $$$2n$$$ vertices $$$V_1, V_2, ..., V_n, W_1, W_2, ..., W_n$$$. $$$V_i$$$ and $$$W_i$$$ represent the state of being in vertex $$$i$$$, but $$$W_i$$$ imposes the additional restriction that you just came from the largest edge.
For a vertex $$$i$$$ let $$$ij$$$ be the largest edge connected with $$$i$$$, and let $$$ik$$$ to be the second largest, or $$$j$$$ if it's the only neighbor. We will add the following edges:
$$$V_i \rightarrow V_j$$$ or $$$W_j$$$ depending on whether $$$ij$$$ is the biggest edge for $$$j$$$ or not.
$$$W_i \rightarrow V_k$$$ or $$$W_k$$$ depending on whether $$$ik$$$ is the biggest edge for $$$k$$$ or not.
The task now simply to count the number of vertices among $$$V_1, V_2, ..., V_n$$$ that end up at $$$V_p$$$ or $$$W_p$$$ after taking $$$k$$$ steps in this state graph. Now we have a bruteforce $$$\operatorname{O}(nk)$$$ solution per query. You can also achieve this complexity by simple brute force.