#P5214. Molecule Splitting in SHTSC

    ID: 18450 Type: Default 1000ms 256MiB

Molecule Splitting in SHTSC

Molecule Splitting in SHTSC

Scientists have recently discovered a highly unstable polymer organic compound called SHTSC. Its molecules are formed by one or more atoms, and atoms are connected by chemical bonds. During the dynamic process, these bonds can break or reconnect with dazzling sound and light effects. However, a surprising property of SHTSC is always maintained: there does not exist an atomic sequence $a_1,a_2,\ldots,a_n\ (n>3)$ such that the bonds $a_1\text{-}a_2$, $a_2\text{-}a_3$, \ldots, $a_{n-1}\text{-}a_n$, and $a_n\text{-}a_1$ are present while there are no other bonds among these atoms.

You are given the initial structure of SHTSC and a series of events in which a chemical bond is either added or removed. The atoms are labeled from 1 to n. After each event, determine how many molecules SHTSC splits into (i.e. how many connected components exist in the current graph structure).

Note: The special property guarantees that the structure never contains an induced cycle of length greater than 3.

inputFormat

The input consists of several parts:

  1. The first line contains three space-separated integers: n (number of atoms), m (number of initial bonds), and q (number of events).
  2. The next m lines each contain two integers u and v representing an initial chemical bond between atoms u and v.
  3. The following q lines each contain an event in the format: t u v, where t is either 1 or 0. If t = 1, a bond between atoms u and v is added. If t = 0, the bond between atoms u and v is removed. It is guaranteed that bond additions and removals are valid (i.e. no redundant additions or removals).

outputFormat

For each event, output a single line with one integer representing the number of molecules (i.e. connected components) after that event.

sample

4 2 3
1 2
3 4
1 2 3
0 1 2
0 3 4
1

2 3

</p>