题目:
Description
判断一个图是否为一个边通图
Input
n 顶点 (n<=100)
边
Output
1 表示连通
0 表示不边通
Sample Input
5
1 2
2 3
5 4
0 0
Sample Output
0
作者思路:和联通分量差不多。
把统计ans变为统计点。
代码:
var a:array[0..101,0..101] of shortint;
ans,n,s,i:longint;
f:array[0..101] of boolean;
procedure init;
var i,j,x,y:longint;
begin
read(n);
{for i:=1 to n-1 do
begin
read(x,y);
a[x,y]:=1;
a[y,x]:=1;
end;}
while (x<>0)and(y<>0) do
begin
read(x,y);
a[x,y]:=1;
a[y,x]:=1;
end;
fillchar(f,sizeof(f),true);
end;
procedure dfs(x:longint);
var i:longint;
begin
for i:=1 to n do
if (i<>x)and(a[x,i]=1)and f[i] then
begin
inc(s); if ans<s then ans:=s;
f[i]:=false; f[x]:=false;
dfs(i);
end;
end;
begin
init;
ans:=1;
dfs(1);
for i:=1 to n do
if f[i] then
begin
write(0);
halt;
end;
write(1);
end.