Pagini recente » Cod sursa (job #142205) | Cod sursa (job #763015) | Cod sursa (job #798345) | Cod sursa (job #1588210) | Cod sursa (job #1089141)
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.