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.
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$$$.
Single integer representing total number of connected components in the graph.
5 3 1 2 1 3 4 5
2
5 0
5
$$$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.
Result : Executed
Feel something is wrong with the test cases?
Result : Accepted
Test Cases :
But to Run or Submit the Problem, you need to Log In.
Continue to Log InYour challenge has been submitted successfully.
You will get a response soon via WhatsApp or Email.
Do let us know your issue.