Maximum component
Practice
3.1 (11 votes)
Fenwick tree
Graphs
Depth first search
Disjoint set union
Algorithms
Problem
48% Success 1174 Attempts 50 Points 1s Time Limit 256MB Memory 1024 KB Max Code

You are given a graph consisting of N nodes. Initially, there is no edge in the graph. You have to process Q queries of the following two types:

  • 1 X Y: connect nodes X and Y with an undirected edge.
  • 2 K: Print the size of the largest connected component if K extra undirected edges are added between any pair of nodes of the graph.

Note that the edges connected in the type 2 query are not considered in further queries.

Note: Since the size of input-output is large, prefer using fast input-output methods.

Input format

  • The first line of input contains denoting the number of nodes and Q denoting the number of queries respectively.
  • Q lines follow. Each of these lines contains an integer type[i], denoting the type of the i-th query. if type[i] is 1, it contains two more integers X, Y,  if type[i] = 2, it contains an integer K.

Output format
For each query of type 2, print the size of the largest connected component in a separate line.

Constraints

\(2 \leq N, Q\leq 4\cdot10^5\\ \\1\leq x_i \lt y_i\le N \\1\le type_i \le 2\\ 1 \leq K \leq N \)

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
8 votes
Tags:
Depth First SearchTreesMathematicsGraphsDynamic ProgrammingAlgorithms
Points:50
8 votes
Tags:
TrieTreeDepth First SearchGraphsAlgorithmsGame Theory
Points:50
13 votes
Tags:
AlgorithmsDepth First SearchDynamic ProgrammingGraphsTrees