#P15937. [TOPC 2021] ICPC Kingdom

[TOPC 2021] ICPC Kingdom

题目描述

The ICPC kingdom has nn cities numbered from 1 to nn, and there are mm roads, numbered from 1 to mm, connecting these cities. Each road connects two cities, and people can travel along the roads in both directions. There are aia_i residents living in city ii. Road jj connects city uju_j and city vjv_j. And the economic benefit of road jj 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 ww workers to fix the roads. Each worker can fix at most one road, and the ii-th worker can only fix one of the roads whose indices are among b1,b2,,bxib_1, b_2, \dots, b_{x_i}.

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 pp and qq such that there is more than one simple path from city pp to city qq. A simple path is a sequence of distinct roads c1,c2,,czc_1, c_2, \dots, c_z such that a trip along c1,c2,czc_1, c_2, \dots c_z will visit exactly z+1z + 1 distinct cities.

The king asked you to calculate the maximum economic benefit if exactly kk roads are fixed without useless roads. You need to calculate for each kk between 1 and n1n - 1.

输入格式

The first line contains nn and mm separated by a white space. nn is the number of cities, and mm is the number of roads. The second line contains nn numbers a1,a2,a3ana_1, a_2, a_3 \dots a_n separated with white spaces indicating the number of the residents in cities 1,2,,n1, 2, \dots, n, respectively. There are mm lines following; each line contains uju_j and vjv_j separated with white space. Road jj connects city uju_j and city vjv_j. The third line contains a number ww indicating the number of workers. The following ww lines indicate the roads that can be fixed by the workers. The (3+i)(3 + i)-th line contains several numbers separated by spaces. The first number is xix_i indicating the number of roads that the ii-th worker can fix. There are xix_i distinct integers b1,b2,,bxib_1, b_2, \dots, b_{x_i} following in that line. The ii-th worker can only fix one of roads b1,b2,,bxib_1, b_2, \dots, b_{x_i}.

输出格式

Print n1n - 1 numbers. The ii-th number printed is the maximum economic benefit if the repair plan fixes exactly ii roads without useless roads; if there is no such plan, you should print 1-1.

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

提示

  • 1n1001 \leq n \leq 100
  • 0m1000 \leq m \leq 100
  • 1ai1091 \leq a_i \leq 10^9
  • 1ui,vin1 \leq u_i, v_i \leq n, uiviu_i \neq v_i
  • 0w1000 \leq w \leq 100