HDU 1213 How Many Tables
来源:互联网 发布:藏宝库源码 编辑:程序博客网 时间:2024/06/08 00:53
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
并查集水题啊................................................
#include<string.h>#include<stdio.h>#include<math.h>using namespace std;int pre[1086];int findboss(int n){ int r=n; while(pre[r]!=r) { r=pre[r]; } int j=n; int temp; while(j!=r)//压缩 { temp=j; j=pre[j]; pre[temp]=r; } return r;}void meg(int x,int y){ int x1=findboss(x); int x2=findboss(y); pre[x1]=x2;//x的boss给y做小弟}int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); for(int i=1; i<=n; i++) pre[i]=i; while(m--) { int x,y; scanf("%d%d",&x,&y); meg(x,y); } int sum=0; for(int i=1; i<=n; i++) { if(pre[i]==i) sum++; } printf("%d\n",sum); }}
阅读全文
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
- 19个必须知道的Visual Studio快捷键
- 继续学习JS啦啦啦
- 【debug】warning C4535: 调用 _set_se_translator() 需要 /EHa
- HDU 4333 浅谈扩展KMP 线性求NXT数组模板
- 存储的瓶颈(7)
- HDU 1213 How Many Tables
- 全排序java
- [bzoj]1092: [SCOI2003]蜘蛛难题
- Box
- 第一次面试体验
- 学习笔记---高等数学前置知识---约分、通分
- 存储的瓶颈(6)
- 51nod 1076 2条不相交的路径 [双联通]【图论】
- C++随记(六)---函数处理数组的一些问题