author | alpar |
Tue, 16 Dec 2003 16:19:08 +0000 | |
changeset 6 | b63d1bc367f7 |
child 8 | cd54905012bc |
permissions | -rw-r--r-- |
alpar@6 | 1 |
#include <iostream> |
alpar@6 | 2 |
#include <graph.h> |
alpar@6 | 3 |
#include <bfs.h> |
alpar@6 | 4 |
|
alpar@6 | 5 |
using namespace NEGRO; |
alpar@6 | 6 |
using namespace std; |
alpar@6 | 7 |
|
alpar@6 | 8 |
typedef Graph<int,int> TestGraph; |
alpar@6 | 9 |
|
alpar@6 | 10 |
int gcd(int a,int b) {int c; while((c=a%b)) {a=b;b=c;} ; return b;} |
alpar@6 | 11 |
|
alpar@6 | 12 |
int main() |
alpar@6 | 13 |
{ |
alpar@6 | 14 |
TestGraph G; |
alpar@6 | 15 |
|
alpar@6 | 16 |
TestGraph::NodeIterator tn,n2; |
alpar@6 | 17 |
|
alpar@6 | 18 |
for(int i=1;i<=5000;i++) |
alpar@6 | 19 |
{ |
alpar@6 | 20 |
*(tn=G.AddNode())=i; |
alpar@6 | 21 |
if(i==2) n2=tn; |
alpar@6 | 22 |
} |
alpar@6 | 23 |
|
alpar@6 | 24 |
for(TestGraph::NodeIterator n(G);n.isValid();++n) |
alpar@6 | 25 |
for(TestGraph::NodeIterator m(G);m.isValid();++m) |
alpar@6 | 26 |
if(gcd(*n,*m)>1) G.AddEdge(n,m); |
alpar@6 | 27 |
|
alpar@6 | 28 |
Bfs<default_bfs_T<TestGraph> > bfs; |
alpar@6 | 29 |
|
alpar@6 | 30 |
bfs.SetG(G); |
alpar@6 | 31 |
bfs.Init(n2); |
alpar@6 | 32 |
bfs.Run(); |
alpar@6 | 33 |
|
alpar@6 | 34 |
for(TestGraph::NodeIterator n(G);n.isValid();++n) |
alpar@6 | 35 |
cout << Get(bfs.tree_map,n).From() << "->" << Get(bfs.tree_map,n).To() |
alpar@6 | 36 |
<< '\n'; |
alpar@6 | 37 |
|
alpar@6 | 38 |
} |