[HDU-1213]How Many Tables
来源:互联网 发布:d3.js可视化 编辑:程序博客网 时间:2024/06/02 02:45
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<vector>#include<stack>#include<queue>#include<map>using namespace std;const int maxn = 1000 + 10;int parent[maxn];int ans;int GetParent(int a) { if( parent[a] != a ) { parent[a] = GetParent( parent[a] ); } return parent[a];}void Merge(int a, int b) { int pa = GetParent( a ); int pb = GetParent( b ); if( pa == pb ) { return ; } ans--; parent[pb] = pa;}int main() { int T; cin >> T; while( T-- ) { int N, M; cin >> N >> M; for(int i=1; i<=N; i++) { parent[i] = i; } ans = N; while( M-- ) { int a, b; cin >> a >> b; Merge( a, b ); } cout << ans << endl; } return 0;}
阅读全文
0 0
- 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 1213how 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
- reflect
- 拉格朗日 & KKT条件
- javascript原型链
- 数据结构-二维数组-三角矩阵压缩存储
- C++基础(1)
- [HDU-1213]How Many Tables
- 用到了的一些Linux小命令
- HDU 3639 Hawk-and-Chicken 强连通缩点+搜索
- MVC
- SourceInsight使用
- 如何在浏览器中控制使用USB摄像头
- Server Tomcat v7.0 Server at localhost was unable to start within 45 seconds
- 在CENTOS7上玩转Ethereum区块链(4):实验前的准备工作
- 哈哈日语 日语入门学习需遵守这六项