Cod sursa(job #1606735)

Utilizator noi_totinoi toti noi_toti Data 20 februarie 2016 14:49:21
Problema Parcurgere DFS - componente conexe Scor 0
Compilator fpc Status done
Runda Arhiva educationala Marime 1 kb
program nustiu;
var n,m:int64;
a:array[0..100,0..100] of int64;
i,j,t,k,c:longint;
f,g:text;
v,z:array[1..100] of int64;
ok:boolean;
begin
  assign(f,'dfs.in');
  reset(f);
  assign(g,'dfs.out');
  rewrite(g);
    read(f,n,m);
      for t:=1 to m do
        begin
          read(f,i,j);
            a[i,j]:=1;
            a[j,i]:=1;
        end;
           i:=1;
           ok:=true;
             repeat
             for j:=1 to n do
               if a[i,j]=1 then
               begin
                 v[j]:=j;
                 ok:=false;
               end;
                 if ok=true then
                  c:=c+1;
                     i:=i+1;
                       for t:=1 to n do
                         if i=v[t] then
                         begin
                           i:=i+1;
                           v[t]:=0;
                           c:=c+1;
                         end
             until(i=n);
             write(g,n-c);
     close(f);
    close(g);
end.