hdu 1213 How Many Tables
2011-11-25 22:03
363 查看
题目:http://acm.hdu.edu.cn/showproblem.php?pid=1213
简单的并查集的应用。。
简单的并查集的应用。。
#include<iostream> using namespace std; int f[1009]; int tt[1009]; int find(int a) { if(a!=f[a]) f[a]=find(f[a]); return f[a]; } int main() { int t; int n,m; int i,a,b; int a_pre,b_pre; char s[10]; cin>>t; while(t--) { cin>>n>>m; for(i=1;i<=n;i++) { tt[i]=0; f[i]=i; } for(i=1;i<=m;i++) { cin>>a>>b; a_pre=find(a); b_pre=find(b); f[a_pre]=b_pre; } getchar(); if(t>=1) gets(s); int ans=0; for(i=1;i<=n;i++) { tt[find(i)]=1; } for(i=1;i<=n;i++) if(tt[i]==1) ans++; printf("%d\n",ans); } return 0; }
相关文章推荐
- 【并查集】 HDU 1213 How Many Tables
- How Many Tables HDU - 1213 (简单并查集)
- HDU -1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- How Many Tables HDU - 1213
- HDU 1213 How Many Tables
- HDU-1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 how many tables
- HDU 1213 how many tables
- HDU 1213 How Many Tables
- 【hdu 1213】How Many Tables
- hdu 1213 How Many Tables
- HDU1213 How Many Tables
- hdu 1213 How Many Tables
- hdu 1213:How Many Tables