Pagini recente » Cod sursa (job #1504097) | Cod sursa (job #3246221) | Cod sursa (job #308680) | Cod sursa (job #1811073) | Cod sursa (job #1089151)
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;
for j:=1 to n-1 do
if b[j]=0 then begin
conex(j);
inc(k);
end;
writeln(k);
close(input);
close(output);
{Totusi este trist in lume}
end.