HDU 1213 How Many Tables(kuangbin带你飞 专题五:并差集)
来源:互联网 发布:网件的访客网络 编辑:程序博客网 时间:2024/05/17 00:17
裸并差集,大意就是要请客什么的,认识的人做一桌,不认识不坐一起,A认识B,B认识C,C认识D这样也算一桌...问需要多少桌....最后找一下有多少个根节点也就是f[i]=i的
#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>#include<algorithm>#include<iostream>using namespace std;int f[2000];int n,m;void inti(){ for(int i=0;i<=n;i++) f[i]=i;}int find(int x){ if(x!=f[x]) return f[x]=find(f[x]); return x;}int main(){ int T; cin>>T; while(T--) { cin>>n>>m; inti(); for(int i=0;i<m;i++) { int u,v; cin>>u>>v; int x=find(u); int y=find(v); if(x!=y) f[x]=y; } int ans=0; for(int i=1;i<=n;i++) { if(f[i]==i) ans++; } cout<<ans<<endl; }}
0 0
- HDU 1213 How Many Tables(kuangbin带你飞 专题五:并差集)
- hdu 1213 How Many Tables ([kuangbin带你飞]专题五 并查集)
- HDU 3038 How Many Answers Are Wrong(kuangbin带你飞 专题五:并差集)
- HDU 1272 小希的迷宫(kuangbin带你飞 专题五:并差集)
- hdu 3038D - How Many Answers Are Wrong [kuangbin带你飞]专题五 并查集
- kuangbin专题五 并查集 POJ 1213 How Many Tables
- POJ 1611 The Suspects(kuangbin带你飞 专题五:并差集)
- POJ 2236 Wireless Network(kuangbin带你飞 专题五:并差集)
- [kuangbin带你飞]专题五 并查集 C HDU 1213
- kuangbin带你飞 专题五 并查集
- [kuangbin带你飞]专题五 【并查集】 【--完结--】
- hdu 1272 小希的迷宫[kuangbin带你飞]专题五 并查集
- [kuangbin带你飞]专题五 并查集 D HDU 3038
- [kuangbin带你飞]专题五 并查集 M HDU 1272
- HDU 1213 How Many Tables(并查集)
- hdu 1213 How Many Tables(并查集练习)
- [ACM] hdu 1213 How Many Tables(并查集)
- [ACM] hdu 1213 How Many Tables(并查集)
- Android 如何使用GPU硬件加速
- Codeforces 508D Tanya and Password 欧拉通路Euler
- windows server2003与2008的区别总结
- Linux学习笔记
- Codeforces Beta Round #63 (Div. 2)
- HDU 1213 How Many Tables(kuangbin带你飞 专题五:并差集)
- Q9.10 To build the tallest stack
- ios 页面传值
- poj1845
- 检测 Linux 内存使用情况的 free 命令的10个例子
- 模型选择与特征选择
- Android 4.4 Graphic Architecture
- Hive严格模式
- 【Android】开发过程中值得注意的问题及解决方案