alpar@6: #include <iostream>
alpar@6: #include <graph.h>
alpar@6: #include <bfs.h>
alpar@6: 
alpar@6: using namespace NEGRO;
alpar@6: using namespace std;
alpar@6: 
alpar@6: typedef Graph<int,int> TestGraph;
alpar@6: 
alpar@6: int gcd(int a,int b) {int c; while((c=a%b)) {a=b;b=c;} ; return b;}
alpar@6: 
alpar@6: int main()
alpar@6: {
alpar@6:   TestGraph G;
alpar@6:   
alpar@6:   TestGraph::NodeIterator tn,n2;
alpar@6:   
alpar@8:   cout << "Create nodes\n";
alpar@8: 
alpar@8:   for(int i=1;i<=500;i++)
alpar@6:     {
alpar@6:       *(tn=G.AddNode())=i;
alpar@6:       if(i==2) n2=tn;
alpar@6:     }
alpar@6:   
alpar@8:   cout << "Create Edges\n";
alpar@8:   
alpar@6:   for(TestGraph::NodeIterator n(G);n.isValid();++n)
alpar@8:     for(TestGraph::NodeIterator m(G);m.isValid();++m) if(n!=m)
alpar@6:       if(gcd(*n,*m)>1) G.AddEdge(n,m);
alpar@6:   
alpar@8:   
alpar@8:   cout << "Run BFS\n";
alpar@8: 
alpar@6:   Bfs<default_bfs_T<TestGraph> > bfs;
alpar@6: 
alpar@6:   bfs.SetG(G);
alpar@6:   bfs.Init(n2);
alpar@6:   bfs.Run();
alpar@6: 
alpar@6:   for(TestGraph::NodeIterator n(G);n.isValid();++n)
alpar@8:     if((*n)!=2)
alpar@8:       cout << (Get(bfs.dist_map,n)) << '\n';
alpar@6: 
alpar@8:   for(TestGraph::NodeIterator n(G);n.isValid();++n)
alpar@8:     if(Get(bfs.dist_map,n))
alpar@8:       cout << *(Get(bfs.tree_map,n).From()) << "->"
alpar@8: 	   << *(Get(bfs.tree_map,n).To())
alpar@8: 	   << '\n';
alpar@6: }