Cod sursa(job #1089141)

Utilizator DjokValeriu Motroi Djok Data 21 ianuarie 2014 15:41:13
Problema Parcurgere DFS - componente conexe Scor 10
Compilator fpc Status done
Runda Arhiva educationala Marime 0.7 kb
   var i,j,n,m,x,y,k:longint;
       a:array[1..1001,1..1001] of byte;
       b:array[1..1001] of byte;

procedure conex(c:longint);
 begin
  b[c]:=1;
  for i:=1 to n do
   if (b[i]=0) and (a[c][i]=1) then conex(i);
 end;



begin
assign(input,'dfs.in');
assign(output,'dfs.out');
reset(input);
rewrite(output);
     read(n); readln(m);
      for i:=1 to m do
       begin
        read(x); readln(y);
         a[x][y]:=1;
         a[y][x]:=1;
       end;
      k:=0;
   for j:=1 to n do
    if b[j]=0 then begin
                     inc(k);
                     conex(j);
                    end;
   writeln(k);


close(input);
close(output);
{Totusi este trist in lume}
end.