求连通分量
Time Limit:1000MS Memory Limit:65536K
Total Submit:234 Accepted:133
Description
求一个图的连通分量
Input
n 顶点数(<=100)
边
Output
连通分量
Sample Input
5
1 2
3 4
2 3
0 0
Sample Output
4
Source
elba
var
i,j,k,n,m,x,y,s,max:longint;a:array[0..100,0..100]of boolean;
b:array[0..100]of longint;
procedure bfs(j:longint);
var
i:longint;
begin
for i:=1 to n do
begin
if (a[i,j]) and (b[i]=0) then
begin
b[i]:=1;
inc(s);
bfs(i);
end;
end;
end;
begin
readln(n);
for i:=1 to n do
for j:=1 to n do
a[i,j]:=false;
repeat
readln(x,y);
a[x,y]:=true;
a[y,x]:=true;
until (x=0) and (y=0);
for i:=1 to n do
begin
s:=0;
bfs(i);
if s>max then max:=s;
end;
writeln(max);
end.