Dijkstra's algorithm

Dijkstra's algorithm is a greedy algorithm for calculating the single source shortest path for a graph. It can also be used to calculate the shortest path spanning tree.

Algorithm
The algorithm is as follows, starting from source $$S$$:
 * 1) Set distance to $$S$$ to 0.
 * 2) While there is a node to be relaxed
 * 3) Find the node V that is the closest to S that is not relaxed.
 * 4) Relax V - Adjust all adjacent vertices

Time complexity of the following algorithm is O(M log N), where M is number of edges and N is number of vertices. Dijkstra can also be implemented as O(n * log (n) + m) using a fibonacci heap, which can be faster, especially with dense graphs.

UM[x] is the total distance between the first vertex and x. S shows which vertices are selected before. A is our matrix that shows the distances. For example, A[i][j] is the distance between i and j.


 * 1) for(all the vertices except the first vertex)
 * 2) UM[j] = A[first vertex][j]
 * 3) UM[first vertex] = 0
 * 4) CLEAR(S)
 * 5) while(our target vertex doesn't exist in S)
 * 6) vertex = vertex with minimum distance that doesn't exist in S
 * 7) add vertex to S
 * 8) for(all the vertices that don't exist in S)
 * 9) if(UM[vertex] + A[vertex][current vertex] < UM[current vertex])
 * 10) UM[current vertex] = UM[vertex] + A[vertex][current vertex];

C++ Implementation
O(m * log(n))

The data structure used here is an adjacency list for a weighted graph.

vector  > > edges:   edges [A] [it] contains all edges: pair < price to go from A to B, B>

C++ Implementation with custom struct
O(m * log(n))