Pls tell error in this code
@Vaibhav277
There were many errors in your code.
- You did not take input into e variable.
- Instead of performing while(e- -), you performed while(n- -) while constructing the graph.
This is wrong because there are e edges in the graph. - While initializing the map, run a loop from 1 to n. Only considering the values present in the graph is wrong because many nodes who were not present in the edges given need to be taken into account too.
- While printing the values, run a loop from 1 to n because many nodes which are not present in the connected component of the source node need to be taken into account too.
This is the modified code.
I hope this answers your query.
If my solution turns out to be helpful, please mark the doubt as resolved.