#P3233. [HNOI2014] 世界树
[HNOI2014] 世界树
Description
The World Tree is an unimaginably huge tree whose sprawling branches form the entire world. Here live various races and beings. They all worship the goddess Alison, who stands for absolute justice and fairness. In their creed, fairness is the fundamental cornerstone that allows the World Tree to thrive and keep running.
The shape of the World Tree can be modeled mathematically: there are races in the World Tree, numbered from to , each living in a settlement also numbered from to , and a race’s number equals its settlement’s number. Some settlements are connected by bidirectional roads, each of length . It is guaranteed that the connections form a tree, that is, every settlement is reachable from every other, and there are no cycles. The distance between two settlements is defined as the length of the unique path connecting them. For example, if there is a road between settlements and , and a road between and , then since each road has length and cycles are impossible, the distance between and is .
For fairness, in year , the king of the World Tree authorizes settlements as temporary offices. For a race (where is the race’s number), if the nearest temporary office to race is at settlement (where is the settlement number of the office), then race accepts the administration of the office at (if multiple temporary offices are at the same minimum distance to that settlement, then is the office with the smallest number among them).
Now the king wants to know, over years, after the authorizations in each year are completed, how many races each temporary office will administer that year (the settlement where an office is located also accepts that office’s administration). This task is handed to you, the wise primate: the programmer. Please help the king complete this task.
Input Format
The first line contains a positive integer , the number of races in the World Tree. The next lines each contain two positive integers , indicating that there is a bidirectional road of length between settlements and . The next line contains a positive integer , the number of years the king queries. Then follow blocks, each consisting of two lines: in the -th block, the first line contains one positive integer , the number of temporary offices authorized in year . The second line contains positive integers , the settlement numbers authorized as temporary offices (guaranteed to be all distinct).
Output Format
Output lines. In the -th line, output integers, where the -th number () is the number of races administered by the temporary office at settlement authorized in year .
10
2 1
3 2
4 3
5 4
6 1
7 3
8 3
9 4
10 1
5
2
6 1
5
2 7 3 6 9
1
8
4
8 7 10 3
5
2 9 3 5 8
1 9
3 1 4 1 1
10
1 1 3 5
4 1 3 1 1
Hint
For of the testdata, , , .
Translated by ChatGPT 5
京公网安备 11011102002149号