Almost Union-Find#2047

Almost Union-Find

1 segundo
128 megabytes
Media (≈1350)

I hope you are familiar with the elegant Union-Find data structure. In this problem, you are required to implement something similar, but not exactly the same.

The data structure you should implement is a collection of disjoint sets that supports three operations:

Initially, there are sets: \{1\}, \{2\}, \{3\}, \ldots, \{n\}.

Entrada

There are several test cases. Each test case begins with a line containing two integers and (1 \leq n, m \leq 100000) — the number of integers and the number of commands. Each of the following lines contains one command. For every operation, 1 \leq p, q \leq n. The size of the input file does not exceed MB.

Salida

For each type command, output two integers: the number of elements and their sum.

Ejemplos

Ejemplo 1

Loading
Loading

Nota

Initially: \{1\}, \{2\}, \{3\}, \{4\}, \{5\}

After operation 1 1 2: \{1,2\}, \{3\}, \{4\}, \{5\}

After operation 2 3 4: \{1,2\}, \{3,4\}, \{5\} (we omit the empty set that results from removing from )

After operation 1 3 5: \{1,2\}, \{3,4,5\}

After operation 2 4 1: \{1,2,4\}, \{3,5\}