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


problem implementing Dijkstra's single source shortest path algorithm

I am trying to implement Dijkstra's single source shortest path algorithm using priority queue data structure and I got stuck at some point.

I am using adjacency list representation of graph, I want to retrieve weight of edge(x,y) how to do it efficiently.

asked 16 Jan '16, 15:30

arpit728's gravatar image

accept rate: 10%

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

answered 16 Jan '16, 17:45

sarvagya3943's gravatar image

accept rate: 36%

edited 16 Jan '16, 17:53


I am coding in java, I am not familiar with STL so I am not getting this code.

(16 Jan '16, 17:51) arpit7281★

I tried explaining the code here with usage of STL specifically. Take a look .

(16 Jan '16, 18:02) sarvagya39434★


why priority queue is declared like this priority_queue<pair<int,int> ,vector<pair<int,int> >pq;

why does it have vector in it.

(16 Jan '16, 20:58) arpit7281★

There are three parameters required here .
1. type of the elements (pair<int,int>)
2. Type of the internal underlying container object where the elements are stored.(that's what vector is used here for )
3. A binary predicate that takes two elements (of type T) as arguments and returns a bool.(this is optional, by default - max priority_queue )

(16 Jan '16, 23:02) sarvagya39434★
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: 16 Jan '16, 15:30

question was seen: 1,959 times

last updated: 16 Jan '16, 23:02