iliya785

bfs

Jun 11th, 2013
49
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.53 KB | None | 0 0
  1. const
  2.   sz = 1000;
  3.  
  4. var
  5.   g:array[0..sz,0..sz] of longint;
  6.   q:array[0..sz] of longint;
  7.   used:array[0..sz] of boolean;
  8.   i,j,n,m,s,e:longint;
  9.  
  10. procedure bfs(v:longint);
  11. var nv:longint;
  12. begin
  13.   fillchar(used,sizeof(used),false);
  14.   s:=0; e:=0; q[0]:=v;
  15.   while (s <= e) do
  16.     begin
  17.       nv:=q[s];
  18.       for i:=1 to n do
  19.         if (g[nv][i] = 1) and (not used[i]) then
  20.           begin
  21.             inc(e);
  22.             q[e]:=i;
  23.             used[i]:=true;
  24.           end;
  25.       inc(s);
  26.     end;
  27. end;
  28.  
  29. begin
  30. end.
Advertisement
Add Comment
Please, Sign In to add comment