#P11545. Intelligence Center Sabotage

    ID: 13634 Type: Default 1000ms 256MiB

Intelligence Center Sabotage

Intelligence Center Sabotage

In country D, there are n cities, and each city has at least one intelligence center installed by country C. In addition, TAC has planned m bidirectional transmission channels. The ith channel is given by a pair \( (a_i, b_i) \), meaning that cities \( a_i \) and \( b_i \) can directly exchange intelligence. It is guaranteed that the network is connected so that any two cities can communicate directly or indirectly.

The enemy forces have launched secret attacks, and some centers may be sabotaged (destroyed). The protocol is as follows: For any channel \( (a, b) \):

  • If both \(a\) and \(b\) are operational, no error messages are generated.
  • If \(a\) is operational but \(b\) is sabotaged, then the active center in city \(a\) will report an error message stating "cannot send information to \(b\)".
  • If \(b\) is operational but \(a\) is sabotaged, then the active center in city \(b\) will report an error message stating "cannot send information to \(a\)".
  • If both centers are sabotaged, no error message is produced.

TAC observes a series of q independent events. In each event, a set of error messages is received. Each error message is of the form \( u\ v \), meaning that the intelligence center in city \( u \) (which is active) reported that it could not send information to city \( v \) (thus \( v \) is sabotaged). It is guaranteed that in every event, there is at least one operational (active) center.

Your task is: For each event, determine the number of sabotaged intelligence centers.

Note: The following consequences hold due to the design of the system. If an active city \( u \) is connected to a city \( v \) and there is no error message reported from \( u \) to \( v \), then city \( v \) must be operational (active). Using this propagation rule, the overall configuration is uniquely determined from the given error messages.

inputFormat

The input begins with a single line containing three integers \( n \), \( m \), and \( q \) \( (2 \le n \le 10^5,\ n-1 \le m \le 10^5,\ 1 \le q \le 10^5) \) — the number of cities, the number of bidirectional transmission channels, and the number of events, respectively.

The next \( m \) lines each contain two integers \( a_i \) and \( b_i \) \( (1 \le a_i, b_i \le n) \) denoting that there is a communication channel between cities \( a_i \) and \( b_i \). It is guaranteed that the network is connected.

Then, \( q \) events follow. Each event starts with a line containing an integer \( k \) \( (0 \le k \le m) \): the number of error messages received in this event. The following \( k \) lines each contain two integers \( u \) and \( v \) \( (1 \le u, v \le n) \), representing that the intelligence center in city \( u \) reported an error message: "cannot send information to \( v \)". This implies that city \( u \) is operational and city \( v \) is sabotaged in the event.

outputFormat

For each event, output a single line containing one integer — the number of sabotaged (destroyed) intelligence centers determined from the error messages.

sample

2 1 1
1 2
1
1 2
1

</p>