You are not logged in. Please login at to post your questions!


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.

asked 20 Apr '17, 13:21

chari407's gravatar image

accept rate: 0%

Answer is hidden as author is suspended. Click here to view.

answered 20 Apr '17, 14:08

marshal_roxx's gravatar image

accept rate: 2%

Well, yes when I tried it this way (vector<pair> thing), it worked fine. But as can be found here - ... vector<vector<pair<>>> will also work. I might have implemented it wrong and i wanted to know where.

(20 Apr '17, 16:21) chari4072★

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

(20 Apr '17, 19:58) marshal_roxx3★

in the line number 13,, your iterator type has to "vp" , not "vvp" ,,, :)


answered 20 Apr '17, 13:36

drexdelta's gravatar image

accept rate: 0%

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

(20 Apr '17, 13:43) drexdelta2★

Just check this out ... it might help you more ,,,

(20 Apr '17, 13:46) drexdelta2★

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?

(20 Apr '17, 16:19) chari4072★

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))

(21 Apr '17, 11:49) drexdelta2★

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


answered 20 Apr '17, 18:29

stevegeek123's gravatar image

accept rate: 25%

@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.

(20 Apr '17, 18:39) chari4072★

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

(20 Apr '17, 18:42) stevegeek1230★
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here



Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text]( "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported
  • mathemetical formulas in Latex between $ symbol

Question tags:


question asked: 20 Apr '17, 13:21

question was seen: 440 times

last updated: 21 Apr '17, 11:49