QOJ.ac

QOJ

Time Limit: 1 s Memory Limit: 32 MB Total points: 100

#11849. Barricades

الإحصائيات

Byteland is an island with a number of cities connected by two-way roads. Road network is designed in such a way, that there is exactly one possibility to drive between any pair of cities (without turning back).

Unfortunately, hard times have come - Byteland is preparing for a war. The Lead Strategiest of Byteland is preparing a plan of defence of Byteland, which takes into account creation of a special security zone. The zone will be created by blocking some of the existing roads in Byteland in such a way, that it won't be possible to drive through these roads. In order to make the zone completely secure, following rules have to be fulfilled:

  • from each city inside the zone it has to be possible to drive to any other city inside that zone,
  • it is not possible to get from a city outside of the zone to the city inside the zone,
  • zone has to consist of exactly $ k $ cities.

Many different solutions to the problem are being considered - for different values of $ k $, it is required to determine how many roads have to be blocked at minimum, to obtain a special security zone of size $ k $ (consisting of exactly $ k $ cities). Help the Lead Strategiest of Byteland - write a program which for specified value of $ k $ calculates required number of barricades.

Write a program which:

  • reads from the standard input description of the roads in Byteland and the set of queries (different $ k $ values),
  • for each query program should determine the minimal possible number of barricades that are sufficient to construct a special security zone of required size,
  • writes result to the standard output.

Input Format

The first line of the standard input contains one integer $ n $ ($1 ≤ n ≤ 3\,000$), representing the number of cities in Byteland. Cities are numbered with numbers $1, 2, \ldots, n $.

Each of the following $ n $ - 1 lines of the standard input contains pair of integers $ a $, $ b $ (1 ≤ $ a $, $ b $ ≤ $ n $) separated with single space. Pair $ a $, $ b $ represents a direct road connecting cities $ a $ and $ b $. Each pair of cities is connected with at most one direct road.

In the following line of the standard input there is an integer $ m $ (1 ≤ $ m $ ≤ $ n $) - it is the number of queries to process. Each of the following $ m $ lines contains one integer $ k_{i} $ ($ k_{i} \in \{1, 2, 3, \ldots, n\}$). It represents query number $ i $ - the number of cities that have to be inside $ i $'th special security zone.

Output Format

Your program should write to the standard output exactly $ m $ numbers, each of them in a separate line. The number in $ i $'th line should be:

  • -1, if creation of a special security zone of size $ k_{i} $ is not possible,
  • the minimal number of roads that have to be blocked in order to construct a special security zone of size $ k_{i} $ otherwise.

Example

Input

7
1 2
1 3
2 4
2 5
3 6
3 7
2
2
3

Output

2
1
About Issues

We understand that our problem archive is not perfect. If you find any issues with the problem, including the statement, scoring configuration, time/memory limits, test cases, etc.

You may use this form to submit an issue regarding the problem. A problem moderator will review your issue and proceed it properly.

STOP! Before you submit an issue, please READ the following guidelines:

  1. This is not a place to publish a discussion, editorial, or requests to debug your code. Your issue will only be visible by you and problem moderators. Other users will not be able to view or reply your issues.
  2. Do not submit duplicated issues. If you have already submitted one, please wait for an moderator to review it. Submitting multiple issues will not speed up the review process and might cause your account to be banned.
  3. Issues must be filed in English or Chinese only.
  4. Be sure your issue is related to this problem. If you need to submit an issue regarding another problem, contest, category, etc., you should submit it to the corresponding page.

Active Issues 0

No issues in this category.

Closed/Resolved Issues 0

No issues in this category.