AlgoUniversity
  • Go Back
Number Of Connected Components :

Author

Sumeet Kumar Mishra

Difficulty Level : Easy

Submissions : 2220

Asked In :

Marks :10

: 35 | : 0

Given an undirected graph $$$G$$$ with $$$n$$$ nodes and $$$m$$$ edges. Find number of connected components.

A connected component is a group of vertices such that within a group each vertex can be reached from another and no path exists between different groups.

Input

First line of input consists of two integers: $$$n$$$ and $$$m$$$, number of nodes and number of edges in the graph respectively.

Next $$$m$$$ lines of input, consists of two integers each: $$$u$$$ and $$$v$$$, indicating there exists an undirected edge between node $$$u$$$ and $$$v$$$.

Output

Single integer representing total number of connected components in the graph.

Examples

Input
5 3
1 2
1 3
4 5
Output
2
Input
5 0
Output
5

Note

$$$1 \leq$$$ $$$n$$$ $$$\leq 100$$$

$$$0 \leq m \leq n.(n-1)/2$$$

$$$1 \leq u, v \leq n$$$

You need to login to view your submissions.

You need to login to view all submissions.

Loading...

Result : Executed

Loading...

Feel something is wrong with the test cases?

Result : Accepted

Test Cases :

You need to Log In
We're glad that you want to attempt this problem!

But to Run or Submit the Problem, you need to Log In.

Continue to Log In
Challenge Submitted!

Your challenge has been submitted successfully.

You will get a response soon via WhatsApp or Email.

Challenge
Facing issue while trying to solve the problem! Don't worry, we got you covered!

Do let us know your issue.

Looks good!
Please enter your issue / feedback.

How do we get in touch with you?
Looks good!
Please enter your phone no.
Looks good!
Please enter your email address.