fork download
  1. #include <iostream>
  2. #include <stdio.h>
  3. #include<boost/graph/adjacency_list.hpp>
  4. #include<boost/graph/dijkstra_shortest_paths.hpp>
  5. #include<boost/graph/graph_traits.hpp>
  6.  
  7.  
  8.  
  9. using namespace boost;
  10.  
  11.  
  12. int main() {
  13. typedef typename boost::adjacency_list<vecS, vecS, directedS, no_property, property<edge_weight_t, int>> graph;
  14. typedef std::pair<int, int> Edge;
  15. //enum { a,b,c,d};
  16.  
  17. Edge edgeArray[] = { Edge(1,2),Edge(2,3),Edge(1,3),Edge(4,1)};
  18. int w[] = { 1,2,5,2 };
  19.  
  20. graph G(edgeArray, edgeArray + sizeof(edgeArray) / sizeof(Edge), w, 4);
  21.  
  22. std::vector<int> d(4);
  23. std::vector<boost::graph_traits<graph>::vertex_descriptor> p(4);
  24.  
  25. graph_traits<graph>::vertex_descriptor source = 1;
  26.  
  27. dijkstra_shortest_paths(G, source,
  28. predecessor_map(make_iterator_property_map(p.begin(), get(vertex_index, G))).distance_map(make_iterator_property_map(d.begin(), get(vertex_index, G))));
  29.  
  30.  
  31.  
  32.  
  33.  
  34.  
  35. }
Success #stdin #stdout 0s 4392KB
stdin
Standard input is empty
stdout
Standard output is empty