标签:ret main str turn name names return bsp style
#include<iostream> using namespace std; const int N=1010; int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[x]); return p[x]; } int main() { int t; int n,m; cin>>t; while(t--) { cin>>n>>m; for(int i=1;i<=n;i++) p[i]=i; while(m--) { int a,b; cin>>a>>b; int pa=find(a); int pb=find(b); if(pa!=pb) p[pa]=pb; } int res=0; for(int i=1;i<=n;i++) if(p[i]==i) res++; cout<<res<<endl; } return 0; }
标签:ret main str turn name names return bsp style
原文地址:https://www.cnblogs.com/QingyuYYYYY/p/12248671.html