Whats wrong with this code?

I wrote this code to simply read the number of vertices ‘n’ and edges ‘e’. I also read information about the e edges. Each edge is also given a cost. when i run it, it says the error is in line 26.
Can some one explain whats the problem ?
The code can be found here

Thanks in advance.

in the line number 13, your iterator type has to “vp” , not “vvp” , :slight_smile:


many errors . you have taken iterator of vector<vector<pair<int,int>>> and g also as vector<vector<pair<int,int>>> . both should be vector<pair<int,int>>::iterator itr and vector<pair<int,int>> g[n] . iteration should be done upto e not n . P.S. :- you can refer to my code for this http://ideone.com/n0CDix


How to ask questions? Don’t have karma. What to do?


There is one more implementation mistake,
in the loop when you are taking edges,
boundary condition has to be “i < e” , not “i < n” …

Just check this out … it might help you more ,

Thanks a lot mate. Can you please explain why the iterator type should be vp and not vvp? I just cant get hold of the reason?

Well, yes when I tried it this way (vector thing), it worked fine.
But as can be found here - https://www.topcoder.com/community/data-science/data-science-tutorials/power-up-c-with-the-standard-template-library-part-2/#dijkstra1 … vector<vector<pair<>>> will also work. I might have implemented it wrong and i wanted to know where.

@stevegeek123 You have to involve yourself in discussions. Answer questions. If your answers are right enough, people vote your answer. Once you get votes, you automatically get karma.

@chari407, thanks for the up vote. I’ll try my best.

okay you got it the way i did . that’s good . as far as getting it done by the way you are trying , iterator has to be for vp not for vvp . and then access the whole vector inside vvp in a separate vp and the iterate with the iterator in the way you did .
But why do so much when an easier way is available . Cheers

Because , you are iterating through the " vector of pairs(vp)" , not “vector of vector of pair(vvp)” .

In simple words , when you want to travel through edges of node ‘i’ , you will be travelling through “graph[i].begin()” to “graph[i].end()”[which is just vector of pair]

, not the entire “graph”(which is vector of (vector of pair))