求连通分量
Time Limit:1000MS Memory Limit:65536K
Total Submit:228 Accepted:128
Description
求一个图的连通分量
Input
n 顶点数(<=100)
边
Output
连通分量
Sample Input
5
1 2
3 4
2 3
0 0
Sample Output
4
-
var a:array[0..1000,0..1000] of longint; b:array[0..1000] of longint; n,m,i,j,k,ans,max,x,y:longint; procedure dp(dep:longint); var i:longint; begin for i:=1 to n do if b[i]=0 then if a[dep,i]=1 then begin b[i]:=1; inc(max); dp(i); end; end; begin readln(n); readln(x,y); while (x<>0) or (y<>0) do begin a[x,y]:=1; a[y,x]:=1; readln(x,y); end; for i:=1 to n do begin max:=0; dp(i); if max>ans then ans:=max; end; writeln(ans); end.