HDUOJ 1213 How Many Tables
来源:互联网 发布:北京市人口普查数据库 编辑:程序博客网 时间:2024/06/07 07:23
How Many Tables
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 33322 Accepted Submission(s): 16634
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 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.
Input
The input starts with an integer T(1<=T<=25) which indicate the number of test cases. Then T test cases follow. Each test case starts with two integers N and M(1<=N,M<=1000). N indicates the number of friends, the friends are marked from 1 to N. Then M lines follow. Each line consists of two integers A and B(A!=B), that means friend A and friend B know each other. There will be a blank line between two cases.
Output
For each test case, just output how many tables Ignatius needs at least. Do NOT print any blanks.
Sample Input
25 31 22 34 55 12 5
Sample Output
24
Author
Ignatius.L
Source
杭电ACM省赛集训队选拔赛之热身赛
Recommend
Eddy | We have carefully selected several similar problems for you: 1325 1198 1863 1162 1879
#include<stdio.h>#include<string.h>int flag[1005],father[1005];int find(int x){if(x!=father[x])father[x]=find(father[x]);return father[x];}void merge(int a,int b){int p=find(a);int q=find(b);father[p]=q;}int main(){int T,N,M;scanf("%d",&T);while(T--){int a,b,i;scanf("%d %d",&N,&M);for(i=1;i<=N;i++){father[i]=i;flag[i]=0;}for(i=1;i<=M;i++){scanf("%d %d",&a,&b);merge(a,b);}int sum=0;for(i=1;i<=N;i++)flag[find(i)]=1;for(i=1;i<=N;i++)if(flag[i])sum++;printf("%d\n",sum);}return 0;}
阅读全文
0 0
- HDUOJ 1213 How Many Tables
- How Many Tables 1213
- 1213 How Many Tables
- 1213:How Many Tables
- hdu 1213 how many tables
- hdu 1213 How Many Tables
- HDOJ 1213 How Many Tables
- hdu 1213 How Many Tables
- HDU 1213 How Many Tables
- hdu 1213 How Many Tables
- hdoj 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
- 【web前端学习】-- JS页面跳转
- Js作用域与作用域链详解
- 大话成像之数字成像系统培训
- 安居客app端抓取数据包 分析数据包的签名 编写爬虫脚本
- [总结]java真是博大精深(四)
- HDUOJ 1213 How Many Tables
- linux && boot
- hdu 4772Zhuge Liang's Password(水题)
- CSS3动画理解与应用
- 应用程序的8个关键性能指标以及测量方法
- Ext JS 6:将日期下拉字段修改为日期时间下拉字段(三)
- 《剑指offer》牛客网java题解-数值的整数次方
- <线段树系列1> codevs 1080 线段树练习
- 百度之星初赛B——Chess