#P15937. [TOPC 2021] ICPC Kingdom
[TOPC 2021] ICPC Kingdom
题目描述
The ICPC kingdom has cities numbered from 1 to , and there are roads, numbered from 1 to , connecting these cities. Each road connects two cities, and people can travel along the roads in both directions. There are residents living in city . Road connects city and city . And the economic benefit of road is $\left\lfloor \sqrt{a_{u_j} + a_{v_j}} \right\rfloor$.
One day, the enemy invaded the ICPC kingdom and destroyed all roads. Fortunately, the ICPC troops defeated the enemy and stopped the invasion. To recover from the war, the king of ICPC hired workers to fix the roads. Each worker can fix at most one road, and the -th worker can only fix one of the roads whose indices are among .
Now the king wants to fix the roads to make the kingdom normal. Considering the cost, the king does not want the repair plan containing any useless road. If a repair plan contains a useless road, there exists a pair of city and such that there is more than one simple path from city to city . A simple path is a sequence of distinct roads such that a trip along will visit exactly distinct cities.
The king asked you to calculate the maximum economic benefit if exactly roads are fixed without useless roads. You need to calculate for each between 1 and .
输入格式
The first line contains and separated by a white space. is the number of cities, and is the number of roads. The second line contains numbers separated with white spaces indicating the number of the residents in cities , respectively. There are lines following; each line contains and separated with white space. Road connects city and city . The third line contains a number indicating the number of workers. The following lines indicate the roads that can be fixed by the workers. The -th line contains several numbers separated by spaces. The first number is indicating the number of roads that the -th worker can fix. There are distinct integers following in that line. The -th worker can only fix one of roads .
输出格式
Print numbers. The -th number printed is the maximum economic benefit if the repair plan fixes exactly roads without useless roads; if there is no such plan, you should print .
5 4
1 2 2 1 4
1 2
2 3
3 1
4 1
3
2 2 4
3 1 2 3
2 1 3
2 3 4 -1
提示
- ,