求连通分量(深搜)
题意
求一个图的连通分量
分析
这题我用深搜
以一个点为起点,搜下去,看它连接哪一个点。每一次tj+1
最后找出最大的连通分量
var
n,i,tao,tj,x,y:longint;
a:array[0..100,0..100]of longint;
f:array[0..100]of longint;
procedure dfs(w:longint);
var
j:longint;
begin
for j:=1 to n do
if (a[j,w]=1)and(f[j]=0) then
begin
f[j]:=1;
inc(tj);
dfs(j);
end;
end;
begin
readln(n);
fillchar(a,sizeof(a),0);
fillchar(f,sizeof(f),0);
repeat
readln(x,y);
a[x,y]:=1;
a[y,x]:=1;
until (x=0)and(y=0);
tao:=0;
for i:=1 to n do
begin
tj:=0;
dfs(i);
if tj>tao then tao:=tj;
end;
write(tao);
end.