luogu#P9096. [PA 2020] Sen o podboju
[PA 2020] Sen o podboju
Problem Description
This problem is translated from PA 2020 Round 2 Sen o podboju.
King Byteur, the ruler of Byteotia, is currently dreaming of conquering Bitotia. Just like in the real world, in his dream he is still far from defeating the enemy. Therefore, he wants to know what he can do to weaken the enemy country...
In his dream, Bitotia consists of cities (numbered from to ), connected by bidirectional roads, and using only these roads it is possible to travel from any city to any other city. In other words, the map of Bitotia forms a tree. However, Byteur does not remember the exact road network of Bitotia... so his mind creates a random road network.
The king concludes that it is a good idea to force Bitotia to split into smaller countries. By a split, Byteur means secretly destroying exactly roads, which will force Bitotia to decompose into smaller countries. These smaller countries are the connected subgraphs formed after removing the selected edges.
However, for the king, destroying just any roads is not enough. Each city of Bitotia has a military coefficient , also imagined by Byteur. Byteur knows that the stronger the military power of a smaller country, the greater the threat it poses to Byteotia. More precisely: if, in a smaller country, the sum of military coefficients of its cities equals , then the threat from this country equals . The total threat to Byteotia equals the sum of threats produced by these smaller countries.
Now Byteur asks you—his dream (literally!) programmer—for help. Please help him compute the minimum possible total threat after splitting Bitotia into countries. Since Byteur has not yet decided the value of the parameter , compute the result for all from to (inclusive).
Input Format
The first line contains an integer , the number of test cases the number of dreams Byteur has. Each test case is described in the same format as follows.
The first line of each test case contains an integer .
The second line contains an integer sequence of length .
The next lines describe the road network of Bitotia. Each line contains two integers , meaning that cities and are connected by a road. It is guaranteed that the input graph is a tree.
Byteur generates the data in the following way. First, he manually chooses an integer , an integer interval , and a value . Then, each test case is generated independently by the following steps:
- The number of cities is chosen uniformly at random from the interval .
- Each is chosen independently and uniformly at random from the interval .
- Generate a sequence of natural numbers . Each element of the sequence is chosen independently and uniformly at random from . Byteur uses it as the Prüfer sequence of the road network, i.e., the Prüfer sequence of the tree given in the test case is .
Output Format
Output lines, describing the answers for each test case. Each line contains integers (where is the number of cities in the input). The -th integer denotes the minimum threat Bitotia can cause after being split into smaller countries.
2
7
9 1 4 2 6 4 7
1 7
6 4
2 3
5 7
3 4
5 3
5
4 8 2 3 1
4 3
3 1
4 2
5 1
1089 545 371 287 227 211 203
324 164 114 102 94
Hint
Explanation of Sample 1
The above testdata was generated using random seed , with parameters .
For the first test case, the first number in the output is , which represents the total threat caused by Bitotia when it is not split. The second number in the output corresponds to the total threat if the road connecting cities and is destroyed; in this case, the threat is .
Data Generation
The sample generator for this problem is provided in the attachment. The generator takes the following as input: the generator seed and the numbers . All testdata for this problem will be generated using an equivalent generator (i.e., using a different pseudo-random library and independent of the compiler implementation).
To ensure randomness of the tests, the values of for each test case are chosen manually, and the generator seed is chosen randomly.
Constraints
This problem uses bundled tests.
For of the data, it is guaranteed that , , , , , .
Translated by ChatGPT 5