Exciting Travel
Time limit2sMemory limit1024 MB
Given a tree and several ordered city lists, find the fewest yacht rides needed so each day's trip never visits the same city twice.
- Level
Medium7 of 10
- Topics
- Tree, Greedy, Binary search
- Solved
- No attempts yet
Problem
After finishing the IODS team selection, you want to travel to a new country to relax. The country contains cities, which are connected by bidirectional roads. There is a unique simple path between any two cities.
In the next days, you wish to explore the country. On each day you have set cities that you wish to visit in order. At the beginning of each day, you can choose any city as the starting city of your trip, and then you need to reach city , then city , ..., and finally city to complete your day's travel.
To add to the fun of the trip, you don't want to pass through a city more than once in a day. At any given moment, you can choose to follow a road from this city to another city, or choose to take a yacht to any city.
You want to know, for each day of travel, the minimum number of yacht rides required in order to avoid passing through the same city more than once. Note that each day's travel is independent: a city passed on the previous day can still be passed on the next day.
Input
The first line contains two integers and (, ).
Each of the next lines contains two integers and (, ), indicating that there is a bidirectional edge between vertices and . It is guaranteed that the given graph is connected.
Each of the next lines describes queries in the format . It is guaranteed that and for all .
The sum of in one test case does not exceed .
Output
For each day, output a single line containing a single integer: the minimum number of yacht rides.
Hint

The figure corresponds to the first sample test case

The figure corresponds to the second sample test case