Pagini recente » Cod sursa (job #2946963) | Cod sursa (job #682491) | Cod sursa (job #1698130) | Cod sursa (job #1908246) | Cod sursa (job #1086966)
program nrdecomponenteconexe;
type sir=array[1..100000]of longword;
var f,g:text;
co:sir;
n,m,i,j,k,x,y:longword;
begin
assign(f,'dfs.in');reset(f);
assign(g,'dfs.out');rewrite(g);
readln(f,n,m);
k:=0;
for i:=1 to n do co[i]:=0;
for i:=1 to m do
begin
readln(f,x,y);
if (co[x]=0)and(co[y]=0) then begin inc(k); co[x]:=k; co[y]:=k; end
else if co[x]=0 then co[x]:=co[y]
else if co[y]=0 then co[y]:=co[x];
end;
for i:=1 to n do
if co[i]=0 then inc(k);
write(g,k);
close(f);
close(g);
end.