Connected Components
Collapse Content
Show Content
Are all the components connected on the given Graph?
A graph is considered one connected component if every node is connected along a path with every other node.
The following graph is not one connected component, since the 1 and 4 cannot be reached from the 0,2,3 and 5.
Input Format
As in the original graph challenges, you will be given a graph in "adjacency-list" style.
The first line of input will contain T, the number of tests cases. T cases will follow, with each case consisting of multiple lines:
- A number
n
on the first line, representing the number of Nodes. n
lines follow, with each linei
representing the Nodes that are connected to Nodei
.
Challenge
Given a graph, print true if the graph is one connected component, and false otherwise.
Please sign in or sign up to submit answers.
Alternatively, you can try out Learneroo before signing up.