(ssl1758)连通图

连通图

Time Limit:1000MS  Memory Limit:65536K
Total Submit:161 Accepted:91

Description

判断一个图是否为一个边通图

Input

n 顶点 (n<=100) 
边 

Output

1 表示连通 
0 表示不边通

Sample Input

5
1 2
2 3 
5 4
0 0

Sample Output

0

Source

elba

var
 a:array[0..100,0..100]of boolean;
 v:array[0..100]of boolean;
 n,i,j:longint;
procedure dfs(i:longint);
var
 j:longint;
begin
 for j:=1 to n do
  if (a[i,j]) and not(v[j]) then
                             begin
                              v[j]:=true;
                              dfs(j);
                             end;
end;
begin
 read(n);
 while not(eof) do
 begin
  readln(i,j);
  a[i,j]:=true;
  a[j,i]:=true;
 end;
 dfs(1);
 for i:=1 to n do
  if not(v[i]) then begin//如果有一个点没走通就是不连通
                          write(0);
                          halt;
                         end;
 write(1)//所有点都走得通就是连通
end.
//详细批注请看上一个求连通变量http://blog.csdn.net/ssl_lzx/article/details/65931127

你可能感兴趣的:(SSL水题收割机(上课作业))