ICPC Kingdom

아직 제출이 없습니다시간 제한2초메모리 제한1024 MB

문제

The ICPC kingdom has nn cities numbered from 11 to nn, and there are mm roads, numbered from 11 to mm, connecting these cities. Each road connects two cities, and people can travel along the roads in both directions. There are a_ia\_i residents living in city ii. Road jj connects city u_ju\_j and city v_jv\_j. And the economic benefit of road jj is a_u_j+a_v_j\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 i-th worker can only fix one of the roads whose indices are among b_1,b_2, ,b_x_ib\_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 c_1,c_2,,c_zc\_1, c\_2, \dots , c\_z such that a trip along c_1,c_2,,c_zc\_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 11 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 a_1,a_2,a_3,,a_na\_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 u_ju\_j and v_jv\_j separated with white space. Road jj connects city u_ju\_j and city v_jv\_j. The third line contains a number ww indicating the number of workers. The following ww line indicates 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 x_ix\_i indicating the number of roads that the ii-th worker can fix. There are x_ix\_i distinct integers b_1,b_2, ,b_x_ib\_1, b\_2, \dots , b\_{x\_i}. following in that line. The ii-th worker can only fix one of roads b_1,b_2, ,b_x_ib\_1, b\_2, \dots , b\_{x\_i}.

출력

Print n1n - 1 numbers. The ii-th number printed is the 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.

제한

  • 1n1001 \le n \le 100
  • 0m1000 \le m \le 100
  • 1a_i1091 \le a\_i \le 10^9
  • 1u_i,v_in1 \le u\_i , v\_i \le n
  • u_i v_iu\_i \ne v\_i
  • 0w1000 \le w \le 100