Implementation of Prim's algorithm in C++
Code looks OK.

I would suggest you to do some class instead of Edge:

//typedef pair&lt;pair&lt;int, int&gt;, int&gt; Edge; //a, b, length
struct Edge{
   int a;
   int b;
   int length;
};


Also I suggest to have some predefined type for vector&lt;Edge&gt;

using EdgeContainer = vector&lt;Edge&gt;;


You have duplication near //find the shortest edge, you probably need Edge there

Here the_shortest is probably not initialized. Also you probably might use something from &lt;algorithm&gt; (but I will do it in same way as you).

    //find the shortest edge
    pair&lt;pair&lt;int, int&gt;, int&gt; the_shortest;
    the_shortest = edges_with_lengths.front();
    for(auto i: edges_with_lengths){
        if(the_shortest.second &gt; i.second)
            the_shortest = i;
    }


Another probably micro optimization would be to write ++i in loops:

//for (int i = 1; i &lt; number_of_nodes; i++)
for (int i = 1; i &lt; number_of_nodes; ++i){
   // ...
}


Also in C++11 main() does not need to return 0;.