Postcards

여러 온라인 계획에서 일부 도로를 지우거나 한쪽 방향으로 막은 뒤, 다른 모든 도시에 도달할 수 있는 도시의 수를 각각 구한다.

어려움8그래프DFS동적 계획법구현아직 제출이 없습니다시간 제한8초메모리 제한256 MB

문제

Bithuania has nn cities connected with mm bidirectional roads. Currently, there exists a path between every pair of cities. In each of these cities there lives a single child. Every child would like to send a Christmas postcard to every other child. Unfortunately, the ongoing Christmas period results in some roads being renovated. Due to difficulties, for some roads, postcards can only be transported in one direction or cannnot be transported along that road at all.

The government of Bithuania gathered a number of plans of road shutdowns. Your task is to find for each of them, one by one, the number of children that are able to get postcards from every other child.

입력

The first line contains three integers n,m,qn, m, q (2n30002 \le n \le 3000, 1m500,0001 \le m \le 500\\,000, 1q500,0001 \le q \le 500\\,000). The next mm lines contain the description of the road network: the ii-th of them contains two integers u_i,v_iu\_i, v\_i (1u_i,v_in1 \le u\_i, v\_i \le n, u_iv_iu\_i \neq v\_i) denoting a road between cities u_iu\_i and v_iv\_i. The roads are numbered 11 through mm with respect to the order of appearance in the input. It is possible that a pair of cities is connected by more than one road.

Then, qq descriptions of road shutdown plans (numbered 11 through qq) follow. The ii-th description starts with a line containing an integer r_ir\_i (1r_i1001 \le r\_i \le 100) -- the number of renovated roads. Next, the description of roads shut down in the ii-th plan follows.1 It consists of r_ir\_i lines; each line describes one road that is shut down and contains three numbers x,p_uv,p_vux, p\_{uv}, p\_{vu} (0x<m0 \le x < m, p_uv,p_vu0,1p\_{uv}, p\_{vu} \in \\{0, 1\\}, p_uv+p_vu1p\_{uv} + p\_{vu} \geq 1). Let us denote by S_iS\_i the sum of answers to the queries about plans 11 through (i1){(i-1)}. Then, the ii-th renovation plan includes the connection j:=((x+S_i),mod,m)+1j := ((x + S\_i)\\,\mathrm{mod}\\,m) + 1. If p_uv=1p\_{uv} = 1, it will be impossible to travel from the city u_ju\_j to the city v_jv\_j using road jj. If p_vu=1p\_{vu} = 1, it will be impossible to travel from the city v_jv\_j to the city u_ju\_j using road jj.

You can assume that for each plan, the values of xx are distinct. Moreover, the sum of values r_ir\_i, over all plans, does not exceed 500,000500\\,000.

1The format of this description is somewhat weird, because we would like to enforce processing the queries online.

출력

For every road shutdown plan, output one line containing the number of children that can receive a postcard from every other child.

힌트

In the first plan we close completely the road 44 (connecting cities 11 and 33) and partially the road 22 (it is not possible to go from 33 to 44). The children from cities 11, 22 and 33 can receive postcards from all other children.

In the second query we have S_2=3S\_2 = 3. Roads 11, 44 and 33 are partially blocked (we disallow going from 11 to 22, from 11 to 33 and from 22 to 33, respectively). Only the child from the city 11 can receive a postcard from all other children.

In the last query S_3=4S\_3 = 4. The road 22 is blocked. In this situation no child can receive a postcard from all other children.