Pls tell error in this code

@Vaibhav277
There were many errors in your code.

  1. You did not take input into e variable.
  2. Instead of performing while(e- -), you performed while(n- -) while constructing the graph.
    This is wrong because there are e edges in the graph.
  3. 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.
  4. 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.