hdu 1213 How Many Tables
2012-09-01 20:13
429 查看
#include<iostream> using namespace std; int father[1005]; int ff(int y) { int t=father[y]; while(t!=father[t]) { t=father[t]; } return t; } void result(int x,int y) { int xx=ff(x); int yy=ff(y); if(xx!=yy) { father[xx]=yy; } } int main() { int t; while(cin>>t) { for(int i=1;i<=t;i++) { int n,m,x,y; int sum=0; cin>>n>>m; for(int j=1;j<=n;j++) { father[j]=j; } for(int j=1;j<=m;j++) { cin>>x>>y; result(x,y); } for(int j=1;j<=n;j++) { if(father[j]==j) sum++; } cout<<sum<<endl; } } }
相关文章推荐
- 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
- 【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
- HDU 1213 How Many Tables
- C - How Many Tables HDU - 1213
- HDU 1213--A - How Many Tables
- HDU 1213 How Many Tables