Bfs- shortest path

what is wrong in this code. I am not able to figure it out.
ide–>https://ide.codingblocks.com/s/199022

@mikkyimran,

  • Line 21: for(auto i:mp){
    As there are n nodes in graph, you have to mark all their distances as -1, as some nodes could not be in mp i.e disconnected, and still we have to print “-1” for them in answer.
    Correction: for (int i = 1 ; i <= n; i++) dist[i] = -1;

  • Line 39: for(int i = 0 ;i<n;i++){
    According to problem, nodes are 1 based indexed,
    Correction: for (int i = 1 ; i <= n; i++){

  • Line 59: g.addedge(u,v);
    You did not took input for u and v.
    Correction: cin >> u >> v, g.addedge(u, v);