Cod sursa(job #1606734)
Utilizator | Data | 20 februarie 2016 14:49:03 | |
---|---|---|---|
Problema | Parcurgere DFS - componente conexe | Scor | 0 |
Compilator | fpc | Status | done |
Runda | Arhiva educationala | Marime | 1.94 kb |
program nou;
var a:array[0..10000,0..10000] of longint;
x,y,i,j:longint;
n,m,c,cc,ccc,ccd:qword;
f,g:Text;
procedure citire;
var i,j,l:integer;
begin
assign(f,'dfs.in');
reset(f);
assign(g,'dfs.out');
rewrite(g);
readln(f,n,m);
for j:=1 to m do
begin
read(f,x,y);
a[x,y]:=1;
a[y,x]:=1;
end;
end;
begin
citire;
c:=0;
cc:=0;
ccc:=0;
for i:=1 to n do
begin
if i<n-1 then
ccc:=0;
for j:=1 to n do
if a[i,j]=1 then
begin
ccc:=ccc+1;
end;
end;
if ccc=0 then
begin
for i:=1 to n-1 do
begin
c:=0;
for j:=i+1 to n do
begin
if a[i,j]=1 then
c:=c+1;
end;
if c=0 then
cc:=cc+1;
end;
for i:=n to n do
begin
for j:=1 to n do
if a[i,j]=1 then
ccd:=ccd+1;
end;
if ccd=0 then
write(g,cc)
else
write(g,cc+1);
end
else
begin
for i:=1 to n-1 do
begin
c:=0;
for j:=i+1 to n do
begin
if a[i,j]=1 then
c:=c+1;
end;
if c=0 then
cc:=cc+1;
end;
write(g,cc);
end;
close(f);
close(g);
end.