#include<iostream> using namespace std; ; int p[N]; int find(int x) { if(p[x]!=x) p[x]=find(p[x]); return p[x]; } int main() { int t; int n,m; cin>>t; while(t--) { cin>>n>>m; ;i<=n;i++) p[i]=i; while(m--) { int a,b; cin>>a…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description 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 fri…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 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,…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 13787 Accepted Submission(s): 6760 Problem Description Today is Ignatius' b…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 有关系(直接或间接均可)的人就坐在一张桌子,我们要统计的是最少需要的桌子数. 并查集的入门题,什么优化都无用到就可以直接过.实质上就是统计总共有多少个不相交的集合.比较可恶的是,题目中 There will be a blank line between two cases 是骗人的!!! #include <iostream> using namespace std; + ; int p[…
传送门 Description 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…
How Many Tables 题目链接: http://acm.hust.edu.cn/vjudge/contest/123393#problem/C Description 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…
Problem Description 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…
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14081 Accepted Submission(s): 6912 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1213 Problem Description 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 frie…
解题思路:和畅通工程类似,问最后还剩下几个不连通的区域. How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15086 Accepted Submission(s): 7364 Problem Description Today is Ignatius' birthday. He invites a…
代码: #include<cstdio> #include<cstring> using namespace std; int n,m; int father[1005]; int Find(int a) { int r=a; while(father[a]!=a) { a=father[a]; } father[r]=a; return a; } void Union(int a,int b) { a=Find(a); b=Find(b); if(a!=b) father[b]=…
题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1213 How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 41546 Accepted Submission(s): 20798 Problem Description Today is Ignatius'…
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 20974 Accepted Submission(s): 10382 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27812 Accepted Submission(s): 13801 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
How Many Tables Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 27455 Accepted Submission(s): 13656 Problem Description Today is Ignatius' birthday. He invites a lot of friends. Now it's dinn…
简单并查集 #include <cstdio> #include <cstring> #define maxn 30005 int fa[maxn],ans[maxn],n,m; int findd( int x ) { return fa[x] == x ? x : fa[x] = findd(fa[x]); } int main() { //freopen("d://in.txt", "r", stdin); int t; scanf(&…