http://acm.split.hdu.edu.cn/showproblem.php?pid=1213
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
using namespace std;
const int maxn=;
int fa[maxn];
int fin(int x)
{
return fa[x]==x?fa[x]:fa[x]=fin(fa[x]);
}
int unin(int x,int y){
return fa[fin(y)]=fin(x);
}
int main()
{
int t,a,b;
int m,n;
cin>>t;
while(t--){
cin>>m>>n;
for(int i=;i<=m;i++){
fa[i]=i;
}
for(int i=;i<n;i++){
scanf("%d%d",&a,&b);
if(fin(a)!=fin(b)){
unin(a,b);
}
} int temp=;
for(int i=;i<=m;i++){
if(fa[i]==i){
temp++;
}
}
cout<<temp<<endl;
getchar();
}
}