>Description
求一个图的连通分量
>Input
n 顶点数(<=100)
>Output
连通分量
>Sample Input
8
6 3
1 2
2 5
5 4
4 1
8 7
0 0
>Sample Output
4
方法一【邻接矩阵DFS】
邻接矩阵,DFS解
#include<iostream>
#include<cstdio>
using namespace std;
bool f[105][105],a[105]; //f邻接矩阵,a给走过的顶点做标记
int m,n,ans;
void ooo(int s)
{
a[s]=1; //标记
for(int i=1;i<=n;i++)
{
if(!a[i]&&f[s][i]) //当两点连通并且此点没有被访问过
{
m++; //累计总数
a[i]=1; //标记
ooo(i); //DFS
}
}
}
int main()
{
int x,y;
scanf("%d%d%d",&n,&x,&y);
while(x&&y) //末尾是0 0时结束输入