fork(1) download
  1.  
  2. #include <iostream>
  3.  
  4. #include <boost/graph/adjacency_list.hpp>
  5. #include <boost/range/iterator_range.hpp>
  6.  
  7. using std::cout;
  8.  
  9. int main() {
  10. boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS> g;
  11.  
  12. add_edge(0, 1, g);
  13. add_edge(1, 2, g);
  14.  
  15. for(auto v : make_iterator_range(vertices(g))) {
  16. cout << v << " has " << degree(v, g) << " neighbor(s): ";
  17. for(auto w : make_iterator_range(adjacent_vertices(v, g))) cout << w << ' ';
  18. cout << '\n';
  19. }
  20. return 0;
  21. }
  22.  
Success #stdin #stdout 0s 3464KB
stdin
Standard input is empty
stdout
0 has 1 neighbor(s): 1 
1 has 2 neighbor(s): 0 2 
2 has 1 neighbor(s): 1