# Include <iostream>
# Include <vector>
# Include <list>
# Include <queue>
# Include <algorithm>
Using namespace STD;
Typedef vector <list <int> graph;
Void BFS (Graph P)
{
Bool visited [P. Size ()];
For (INT I = 0; I! = (INT) p. Size (); I ++)
{
Visited [I] = false;
}
Queue <int> que;
If (P. Empty ())
{
Return;
}
Que. Push (0 );
While (! Que. Empty ())
{
Int visiting_point = que. Front ();
Que. Pop ();
If (! Visited [visiting_point])
{
Cout <visiting_point <Endl;
Visited [visiting_point] = true;
For (list <int >:: iterator iter = P [visiting_point]. Begin ();
ITER! = P [visiting_point]. End (); ITER ++)
{
Que. Push (* ITER );
}
}
}
}
Int main ()
{
Graph graph;
List <int> list0;
List0.push _ back (2 );
List <int> list1;
List1.push _ back (2 );
List <int> list2;
List2.push _ back (0 );
List2.push _ back (1 );
Graph. push_back (list0 );
Graph. push_back (list1 );
Graph. push_back (list2 );
BFS (graph );
Return 0;
}
This is the first BFS attempt. Just practice it :)