map is more useful when the limits on inputs are too high. For example you can’t take an array of size 10^9 but with map you can do it directly.
So it’s just the size, which is why I used map. But you can replace map with vector of array here. It doesn’t really matter 
please provide vector implementation im unable to understand role of map
one query-> s = q.front();
q.pop();
it should be
q.pop(); then
q.front();
am i right?
Yes, you are right! I fixed it. Thanks 
vector adj[10]; it same like vector<vector> adj(10)… ?
code is not working fine for input
5 3
1 2
1 3
2 4
it gives output 2 3 1 4
vectoradj[10] means we are taking an array of vectors and vector<vector >adj(10) means we are taking a vector of vector and we have already put 10 elements in the vector to initialise it.
Yes, both will do same work.
In first vector adj[10] :
we are making array of vector(vector containing integer) therefore,
adj[0] -> vector
adj[1] -> vector and so on.
In second we are making vector of size 10 whose each element will be vector which is equivalent to array of vector as above therefore here also,
adj[0] -> vector
adj[1] -> vector and so on
what should be prefer? arrays of vector or vectors of vectors?
You need to mark the starting vertex as visited initially. Rest seems fine
1 Like
nice…thanks a lot for amazing help.
how can i deal with this bfs problem- TRATCK1 Problem - CodeChef
1 Like
It is a DFS problem. Simply find the no of components in the graph.
you are gettin WA…because if n==0 then ans=0 not 1.
how can i access map as a vector means how can i use map as vector there?how to access?
why we are getting wa,please help us