http://acm.hdu.edu.cn/showproblem.php?pid=1213
#include<iostream>
#include<math.h>
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
struct point
{
int x;
int y;
int index;
} point[2000];
int pre[2000];
int mark[2000];
int n,d;
int num[10000];
void init(int n)
{
for(int i=1;i<=n;i++){
pre[i]=i;
}
}
int find(int x)
{
return x==pre[x]?x:pre[x]=find(pre[x]);
// find 函数
}
void unions(int x,int y)
{
int fx=find(x);
int fy=find(y);
if(fx!=fy)
{
pre[fx]=fy;
}
//union函数
}//并查集方法;
int main()
{
int t;
cin>>t;
while(t--)
{
int n,m;
cin>>n>>m;
init(n);
for(int i=0; i<m; i++)
{
int a,b;
cin>>a>>b;
unions(a,b);
}
int ans=0;
for(int i=1;i<=n;i++){
if(find(i)==i)ans++;
}
cout<<ans<<endl;
}
return 0;
}