All Tracks Algorithms Graphs Depth First Search Problem

Monk and Graph Problem
Tag(s):

Algorithms, DFS, Easy, Graph Theory

Problem
Editorial
Analytics

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\)

SAMPLE INPUT
6 3
1 2
2 3
4 5
SAMPLE OUTPUT
2
Explanation

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
Marking Scheme: Marks are awarded when all the testcases pass.
Allowed Languages: C, C++, C++14, Clojure, C#, D, Erlang, F#, Go, Groovy, Haskell, Java, Java 8, JavaScript(Rhino), JavaScript(Node.js), Julia, Kotlin, Lisp, Lisp (SBCL), Lua, Objective-C, OCaml, Octave, Pascal, Perl, PHP, Python, Python 3, R(RScript), Racket, Ruby, Rust, Scala, Swift, Visual Basic

CODE EDITOR

Initializing Code Editor...
Your Rating:

Contributor

This Problem was Asked in

HackerEarth

Challenge Name

CodeMonk (Graph Theory Part I)

OTHER PROBLEMS OF THIS CHALLENGE
Notifications
View All Notifications

?