Component Sum

View as PDF

Submit solution

Points: 12 (partial)
Time limit: 2.0s
Memory limit: 64M
PyPy 2 128M
PyPy 3 128M

Author:
Problem types

You have a graph of N nodes and Q queries.

Queries will be in two types:

1 x y: Add an edge between nodes X and Y (1 \leq X,Y \leq N, X\neq Y).

2 k: Print the sum of the sizes of the connected components whose sizes are less than or equal to K (1 \leq K \leq N).

Input Specification

The first line will contain two integers N and Q (2 \leq N,Q \leq 2\cdot 10^5).

The next Q lines will contain a query of one of the two types described above.

Output Specification

You are to print one line for each type 2 query: the sum described in the problem statement.

Subtasks

Subtask 1 (30%)

N,Q \leq 100

Subtask 2 (70%)

No further constraints.

Sample Input

5 5
1 1 2
2 1
1 2 3
1 4 5
2 2

Sample Output

3
2

Comments

There are no comments at the moment.