#P10304. [THUWC 2020] 道路修建
[THUWC 2020] 道路修建
Problem Description
Country is an ancient nation. There are cities in this country, numbered from to . City is the capital, and it is also the only city with a port. Imported goods enter through the capital’s port and are then transported to other cities.
To make the transportation of imported goods easier, the king of Country plans to build some one-way roads specifically for transporting goods. Soon, the ministers of Country proposed a road construction plan: the plan consists of one-way roads, and using these roads, one can travel from City to any other city in the country. Very specially, the road network formed by these roads has no cycles.
Due to limited finances, the king of Country plans to first choose roads from the roads to build, to ensure basic transportation capacity. He uses a method similar to depth-first search to determine the roads to be built with higher priority:
First, let the set contain only City , and set the current city to be City .
Then, choose a road that starts from the current city and ends at a city that is not in set . Mark this road as a priority road to be built, add city into set , and set the parent of city to be the current city .
Finally, change the current city to city . If there are multiple choices for city , choose the one with the smallest city index; if there is no selectable city , then change the current city to the parent of .
Repeat the above operations until all cities have been added into set , then stop.
It can be seen that the above steps select exactly priority roads, and these priority roads form a tree structure rooted at the capital. We call these priority roads the tree roads.
As the economy develops, Country gradually completes the entire road network consisting of the roads. However, the tree roads, since they were built earlier, often need maintenance. The ministers of Country proposed possible maintenance plans. Each maintenance plan requires maintaining all tree roads between city and city , and it is guaranteed that city is an ancestor of city in the tree. Such a maintenance plan will have a large impact on the subtree rooted at city . The king of Country wants you to evaluate each possible maintenance plan: compute, when all tree roads between city and city are unusable, how many cities in the subtree rooted at city will become unreachable from the capital?
Input Format
The first line contains three integers , representing the number of cities in Country , the number of roads in the construction plan, and the number of maintenance plans.
The next lines each contain two integers , indicating a one-way road from to in the construction plan.
The next lines each contain two integers , indicating a maintenance plan.
The input guarantees that:
- The given construction plan ensures that every city in Country is reachable from the capital, and there are no cycles in the plan.
- Between any two cities, there is at most one road, and the endpoints of each road have different city indices.
- In each maintenance plan, city is guaranteed to be some ancestor of city in the tree structure formed by the tree roads.
Output Format
Output lines, each containing one integer, indicating for each maintenance plan how many cities in the subtree rooted at city will be unreachable from the capital.
3 3 2
1 2
2 3
1 3
1 2
1 3
1
0
Hint
Subtasks
| Subtask ID | Score | Special Constraints |
|---|---|---|
| , | ||
| It is guaranteed that in each maintenance plan, city is the parent of city . | ||
| It is guaranteed that the maintenance plans satisfy . | ||
| None. |
For of the data, , .
Translated by ChatGPT 5