标签:imp return limit tables tle 并查集 amp author case
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 30551 Accepted Submission(s):
15140
#include<iostream> #include<cstdio> #include<cstring> using namespace std; int far[1009]; int f(int x) { return far[x]==x?x:f(far[x]); } int n,m,tot,t; int main() { scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m)&&n; for(int i=1;i<=n;i++) far[i]=i; for(int i=1;i<=m;i++) { int x,y; scanf("%d%d",&x,&y); int p=f(x),q=f(y); if(p!=q) { far[p]=q; n--; } } printf("%d\n",n); } return 0; }
标签:imp return limit tables tle 并查集 amp author case
原文地址:http://www.cnblogs.com/zzyh/p/6973103.html