Pagini recente » Cod sursa (job #2060304) | Cod sursa (job #3210626) | Cod sursa (job #817505) | Cod sursa (job #2566676) | Cod sursa (job #1086932)
program nrdecomponenteconexe;
type sir=array[1..1000]of word;
var f,g:text;
co:sir;
n,m,i,j,k,x,y:word;
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.