https://ide.codingblocks.com/s/248167 Run error
Https://ide.codingblocks.com/s/248167
@Shlok bro what you are doing is adding just the components of a graph. The n is given for a reason, what you are considering is just m.
For example let’s modify the sample input given:-
4 2
1 2
1 3
4
Now according to your code your adjacency list just contains 1-2, 2-1, 1-3, 3-1 but 4 is also a legit vertex and is one of the connected component, but you haven’t considered it. No when the source vertex is 4 as in above it will give null pointer exception.
n is not given just for input sake, it is the number of vertices in graph.
Ohhhh alright… I’ll give it a try
@Shlok Or buddy lemme know i will send my code for your reference so that all other questions can be done by you fluently!
Bro i just cant think how to do it… Can u send ur code for reference… I will make changes in my code accordingly
@Shlok Bro pfa the code below, see the code correct your graph or watch the video lecture for graph again.
For graph refer the lecture, and resolve the doubt bro!