title: Dijkstra boost distance map gives random values
body: <p>I am trying to solve the problem where I am given:</p>
  
  <ol>
  <li><strong>a graph</strong> with <strong>v vertices</strong> and <strong>e edges</strong> and the <strong>edge weights</strong>.</li>
  </ol>
  
  <p><strong>Output:</strong></p>
  
  <ol>
  <li>the weight of the minimum spanning tree</li>
  <li>the distance between the first node(0) and the farthest node(which can be any node except 0)</li>
  </ol>
  
  <p><strong>Problem:</strong></p>
  
  <p>My distance map just stores a random unknown number.</p>
  
  <p><strong>My input is:</strong></p>
  
  <pre><code>5
  5 6
  0 1 1
  0 2 2 
  1 2 5
  1 3 1
  3 2 2
  2 4 3
  4 5
  1 0 91
  2 0 50
  2 1 849
  3 0 451
  3 1 724
  8 25
  1 0 91
  2 0 176
  2 1 658
  3 0 61
  3 1 740
  4 0 21
  4 1 817
  4 2 407
  4 3 469
  5 0 468
  5 1 493
  5 2 400
  5 3 814
  5 4 86
  6 0 611
  6 1 457
  6 2 776
  6 4 452
  6 5 4
  7 0 601
  7 2 722
  7 3 11
  7 4 249
  7 5 530
  7 6 632
  9 9
  1 0 64
  3 1 914
  4 1 331
  4 2 824
  5 3 509
  7 5 520
  7 6 460
  8 1 415
  8 7 263
  3 2
  1 0 533
  2 1 920
  </code></pre>
  
  <p>The first number is the number of testcases,then for each testcase I have the number of vertices and edges,followed by the vertice number(2 of the denoting an edge) and the respective weights.</p>
  
  <p><strong>Example:</strong></p>
  
  <pre><code>testcases
  
  no_vert no_edges
  
  node_1 node_2 weight_1
  node_2 node_3 weight_2
  ect....
  </code></pre>
  
  <p><strong>Output: is the weight of spanning tree and the distance between first and farthest node:</strong></p>
  
  <pre><code>7 5
  592 451
  450 176
  3386 1262
  1453 1453
  </code></pre>
  
  <p>So instead of this correct output I get:</p>
  
  <pre><code>7 5
  592 2147483647
  450 2147483647
  3386 2147483647
  </code></pre>
  
  <p>Which means there is a problem with my dijkstras approach. I am not where there is a mistake,I assume it is with the distance vector,but where?</p>
  
  <p>Here is my <strong>code</strong></p>
  
  <pre><code>//============================================================================
  // Name        : boost_ex_1.cpp
  // Author      : priya
  // Version     :
  // Copyright   : Your copyright notice
  // Description : Hello World in C++, Ansi-style
  //============================================================================
  
  #include &lt;iostream&gt;
  
  #include&lt;vector&gt;
  #include&lt;algorithm&gt;
  #include&lt;boost/graph/adjacency_list.hpp&gt;
  #include&lt;boost/graph/prim_minimum_spanning_tree.hpp&gt;
  #include&lt;boost/graph/dijkstra_shortest_paths.hpp&gt;
  #include&lt;boost/graph/kruskal_min_spanning_tree.hpp&gt;
  
  using namespace std;
  using namespace boost;
  
  typedef adjacency_list&lt;vecS, vecS, directedS, no_property,property&lt;edge_weight_t, int&gt; &gt; Graph;
  
      //vertex and edge descriptor
      typedef graph_traits&lt;Graph&gt;::vertex_descriptor Vertex;
      typedef graph_traits&lt;Graph&gt;::edge_descriptor Edge;
  
  
  int testcases();
  
  int main() {
      ios_base::sync_with_stdio(false);
      int n=0;
      cin&gt;&gt;n;
      while(n--)
      {
          testcases();
      }
  
      return 0;
  }
  
  
  int testcases()
  {
      //creation of graphs
  
  
      //get number of edges and vertices
  
      int NEDGES,NVERT;
      cin&gt;&gt;NVERT&gt;&gt;NEDGES;
  
      //graph g
  
      Graph g(NVERT);
      Vertex SOURCE=0;
      int a,b,c;
  
      //property map for edge weights
      property_map&lt;Graph,edge_weight_t&gt;::type weightMap = get(edge_weight,g);
  
      //fill graph details in g
  
      for(int i=0;i&lt;NEDGES;++i)
      {
          cin &gt;&gt; a &gt;&gt; b &gt;&gt; c;
          bool success;
          Edge e;
          tie(e,success) = add_edge(a,b,g);
          weightMap[e]=c;
      }
  
  //filled graph with edges and vertices and weight in weightMap
  
      vector&lt;Edge&gt; spanning_tree;
      kruskal_minimum_spanning_tree(g,back_inserter(spanning_tree));
  
      a=0;
  
      for(vector&lt;Edge&gt;::iterator ei=spanning_tree.begin();ei!=spanning_tree.end();++ei)
      {
          a+=weightMap[*ei];
      }
  
  
      vector&lt;int&gt;distancep(NVERT); //distance ebtween nodes
  
      dijkstra_shortest_paths(g,SOURCE,distance_map(&amp;distancep[0]));
      b=0;
  
      for(int i=0;i&lt;num_vertices(g);++i)
      {
  
        b=max(b,distancep[i]);
      }
  
  
      cout &lt;&lt; a &lt;&lt;" "&lt;&lt; b &lt;&lt; endl;
  
  
  
  
      return 0;
  
      }
  </code></pre>
  
  <p>I would be very grateful if anyone could help me.</p>
  
  <p>Thank you.</p>
  
  <p><strong>EDIT::</strong> <em>In addition as you can see in my output,the last output is missing,Im also not able to figure out why.Thank you</em></p>