Implementation of Dijkstra's algorithm in C++
Design

So not really Dijkstra algorithm.

while (visited.size() &lt; number_of_nodes)


This condition may not be met in all graphs (if there is a subset of nodes not connected to other nodes).

Also Dijkstra uses two lists.


List of nodes that have been visited. (starts empty)
A sorted frontier list.


You have the 1st list but seem to cobbling the second list out of thin air each iteration.

Code Review.

int dijkstra(vector&lt;vector&lt;int&gt;&gt; graph, int source, int target) {


Sure. You are returning the shortest length from source to target. But would it not be more interesting to return the path most of the time.

Also a graph being a vector of vector of int is a bit restrictive. You could have created a concept of a graph. Then templatized the algorithm based on the concept. Then writing a wrapper for vector of vector of int to implement the concept would have been trivial.

// Concept.
Graph
    Node const&amp; getNode(int id) const // returns a reference to a node.

Node
    int edgeCount() const             // returns number of outbound edges
    Edge const&amp; getEdge(int id) const // returns a reference to an edge

Edge
    int getDst() const               // returns the id of the dst vertices.
    int getCost() const              // returns the cost from this node to dst.


Algorith for Dijkstra

template&lt;typename Graph&gt;
vector&lt;int&gt; dijkstra(Graph const&amp; graph, int start, int end)
{
    std::vector&lt;int&gt;                seen;
    std::priority_queue&lt;Frontier&gt;   frontierList;

    frontierList.push({start, 0, {start}});

    while(!frontierList.empty())
    {
        Frontier  head = frontierList.top();
        frontierList.pop();

        if (head.location == end) {
            return head.path.append(end);
        }

        if (std::find(std::begin(seen), std::end(seen), head.location) != std::end(seen)) {
            continue;
        }

        for(int loop=0;loop &lt; graph.getNode(head.location).edgeCount(); ++loop) {
            auto const&amp; edge = graph.getNode(head.location).getEdge(loop);
            frontierList.push({edge.getDst(),
                                 head.cost + edge.getCost(),
                                 head.path.append(head.location)});
        }
    }
    return {}; // empty path as none was found.
}