All Tracks Algorithms Graphs Depth First Search Problem

Monk and Graph Problem

Algorithms, Depth-first search, Graph, Graph Theory


Monk and his graph problems never end. Here is one more from our own Monk:
Given an undirected graph with N vertices and M edges, what is the maximum number of edges in any connected component of the graph.
In other words, if given graph has k connected components, and \(E_1,E_2,....E_k\) be the number of edges in the respective connected component, then find \(max(E_1,E_2,....,E_k)\) .

The graph may have multiple edges and self loops. The N vertices are numbered as \(1,2,...,N\).

Input Format:
The first line of input consists of two space separated integers N and M, denoting number of vertices in the graph and number of edges in the graph respectively.
Following M lines consists of two space separated each a and b, denoting there is an edge between vertex a and vertex b.

Output Format:
The only line of output consists of answer of the question asked by Monk.

Input Constraints:
\(1 \le N \le 10^5\)
\(0 \le M \le 10^5\)
\(1 \le a,b \le N\)

6 3
1 2
2 3
4 5

The graph has 3 connected components :
First component is \(1-2-3\) which has 2 edges.
Second component is \(4-5\) which has 1 edge.
Third component is 6 which has no edges.

So, answer is \(max(2,1,0)=2\)

Time Limit: 1.0 sec(s) for each input file.
Memory Limit: 256 MB
Source Limit: 1024 KB

Best Submission

Similar Problems


This Problem was Asked in

Initializing Code Editor...
View All Notifications