Farmer John has just purchased a car equipped with an autopilot system. He is so excited about this high-tech product and can’t wait to try it. John plans to travel to another city this weekend, so he decides to let the autopilot system lead the way.
There are $N$ cities numbered from 1 to $N$ inclusively. John lives in city 1 and he plans to travel to city $N$. The cities are connected by $N-1$ highways. Any two cities are reachable to each other via the highways. Every time John passes through a high way, he needs to pay 1 unit of money as the toll fee.
Obviously, such a road system is very busy, since there is only one path between two cities. To solve this problem, $M$ cities are selected as transport hubs. For each city $i$ (including the hubs), $M$ new one-way roads are constructed, each of which allows travelling from city $i$ to one of the hubs, but travelling from the hub back to the city is not allowed. More importantly, they are free of charge!
Now Farmer John has started the autopilot system, waiting for it to lead him from city 1 to city $N$. Unfortunately, something goes wrong with its software, so it would pilot at random. When the car is located in a city, the system will pick the next destination as the following. For the $i-th$ transport hub, the system will select it as the next destination with probability $q_i$, and travel to the hub via the free one-way road. If none of the transport hubs is selected, it drives the car to one of the neighboring city through a highway with uniform probability. In other words, denoting the sum of $q_i$ as $Q$ and the city has $K$ neighbors, the probability of traveling to one of the neighboring cities is $\frac{(1-Q)}{K}$. The only good news is that the system will stop piloting immediately when the car arrives in city $N$.
Farmer John is aware of this malfunctioning now. He wants to know the expected amount of money that he needs to pay for the toll fee, if he lets the car travel at random as described above.