Sunday, March 24, 2013

Dikstra implementation using stl


Dijkstra algorithm can be used to find shortest distance in a graph when the edges have non negative weights. The very good reference for understanding Dijkstra algorithm is on GeeksforGeeks. But they have implemented it using adjacency matrix. We can use STL also for implementing this algorithm which uses adjacency list. So i am giving you the code for implementing Dijkstra algorithm using stl.






After understanding this code just try the Highways. on spoj. It will be solved easily by doing few changes to the code :)

References:-
1. Ronzii's Blog
2. GeeksforGeeks