Airline
Time limit15sMemory limit512 MB
Given a tree of n airports, for each query adding a flight between x and y, count the airport pairs whose shortest distance decreases.
Problem
An airline operates regular flights that connect different airports. Each flight links two airports directly (without stopping at any other airport) and can be used in both directions. The flights are arranged so that for any starting airport and destination airport , there is exactly one sequence of flights between them that does not visit any airport more than once. The number of flights in this sequence is called the distance between and .
If the airline adds a flight between airports and , some pairs may get a shorter route. The more pairs affected, the more valuable the new connection is. The airline asks you to evaluate several candidate additions by this measure.
Input
The first line contains two integers and . The next lines each contain two integers and , a direct flight between airports and . The last lines each contain two integers and . In the -th scenario, a direct flight between and is added to the original flights.
Output
Output lines. The -th line contains the number of pairs with whose distance decreases when a direct flight between and is added to the original flights.
Constraints
- ; ;
- ; ;
- , where is the distance between and in the original flight network.