How Many Tables(HDU
来源:互联网 发布:centos vsftpd 编辑:程序博客网 时间:2024/05/16 10:45
一、题目大意
一句话概括:好朋友才能做到一张桌子上。
a和b是好朋友,b和c是好朋友,那么a和c是好朋友,坐在一个桌子上。d和e是好朋友,但是没有人和a,b,c中的一人是好朋友,所以d和e在一张桌子上。
问:需要最少的桌子数。
二、题目分析
比较基础的并查集。
三、附加代码
#include<iostream>#include<cstdio>#include<algorithm>#include<stack>#include<queue>#include<cstring>#include<string>#include<set>#include<cmath>#include<map>#include<sstream>using namespace std;#define inf 0x3f3f3f3ftypedef long long LL;const int maxn = 1000 + 8;int par[maxn];int t,n,m,a,b,num;int Find(int x){ return x == par[x] ? x : par[x] = Find(par[x]);}void Unite(int x,int y){ x = Find(x); y = Find(y); if(x == y) return; par[y] = x;}int main(){ scanf("%d",&t); while(t--){ scanf("%d%d",&n,&m); num = 0; for(int i = 1; i <= n; ++i) par[i] = i; for(int i = 0; i < m; ++i){ cin >> a >> b; Unite(a,b); } set<int> p; for(int i = 1; i <= n; ++i){ p.insert(Find(i)); } cout << p.size() << endl; }}
阅读全文
0 0
- hdu How Many Tables
- HDU How Many Tables
- HDU How Many Tables
- hdu how many tables
- How Many Tables HDU
- How Many Tables HDU
- HDU-How Many Tables
- How Many Tables HDU
- How Many Tables(HDU
- How Many Tables HDU
- How Many Tables HDU
- HDU 1273 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
- sdut 保留整数
- 基于JS的AB测试方案
- at命令
- Python打包分发工具setuptools简介
- Intervals (差分约束)
- How Many Tables(HDU
- HDU 1671 Phone List(字典树)
- 友盟 分享
- 算法基础-字符移位
- LocationManager的使用
- Java中的static关键字解析
- mysql基本使用
- 如何解决斐波那契数列递归方法的性能问题
- 淘宝框架atlas集成