How Many Tables
来源:互联网 发布:交易圣经知乎 编辑:程序博客网 时间:2024/05/01 08:26
Today is Ignatius' birthday. He invites a lot of friends. Now it's dinner time. Ignatius wants to know how many tables he needs at least. You have to notice that not all the friends know each other, and all the friends do not want to stay with strangers.
One important rule for this problem is that if I tell you A knows B, and B knows C, that means A, B, C know each other, so they can stay in one table.
For example: If I tell you A knows B, B knows C, and D knows E, so A, B, C can stay in one table, and D, E have to stay in the other one. So Ignatius needs 2 tables at least.
One important rule for this problem is that if I tell you A knows B, and B knows C, that means A, B, C know each other, so they can stay in one table.
For example: If I tell you A knows B, B knows C, and D knows E, so A, B, C can stay in one table, and D, E have to stay in the other one. So Ignatius needs 2 tables at least.
25 31 22 34 55 12 5
24
终于有道我能做的题了QAQ,水水更健康。就是判断一下有几个集合,,,也就是有几个根。。。
#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;const int N = 1010;int f[N], num[N];int Find(int x){ if(x != f[x]) f[x] = Find(f[x]); return f[x];}void Union(int x, int y){ int fx = Find(x); int fy = Find(y); if(fx != fy) f[fx] = fy;}int main(){ int t, n, m; int a, b; scanf("%d", &t); while(t--) { memset(num, 0, sizeof(num)); scanf("%d%d", &n, &m); for(int i = 1; i <= n; i++) f[i] = i; while(m--) { scanf("%d%d", &a, &b); Union(a, b); } for(int i = 1; i <= n; i++) num[Find(i)] = 1; int cnt = 0; for(int i = 1; i <= n; i++) cnt += num[i]; printf("%d\n", cnt); } return 0;}
阅读全文
0 0
- How Many Tables
- HDOJ How Many Tables
- hduoj1213:How Many Tables
- hdu How Many Tables
- HDU1213:How Many Tables
- HDU1213--How Many Tables
- hdu1213-How Many Tables
- hdu1213 How Many Tables
- HDU How Many Tables
- hdu_1213 How Many Tables
- hdu1213 How Many Tables
- How Many Tables
- How Many Tables
- HDU How Many Tables
- HDU1213 How Many Tables
- hdu1213 How Many Tables
- How Many Tables
- How Many Tables 1213
- MySQL SELECT执行顺序
- jquery的ajax获取php文件
- 遇到xml文件不编译,需要在pom.xml文件中配置
- AsyncTask
- table与div互相嵌套注意
- How Many Tables
- 学生选课统计练习java
- UI自动化体系建设的创新实践
- 404,500等HTTP状态码表示的含义
- Oracle学前班
- Linux功耗管理(7)_Wakeup events framework
- HDU6128Inverse of sum
- Oracle数据库exp与expdp方式导入导出时改变数据库表空间及用户信息
- caffe自定义神经层