Hdu 1213 How Many Tables, hdu1213

Source: Internet
Author: User

Hdu 1213 How Many Tables, hdu1213
How Many TablesTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission (s): 12689 Accepted Submission (s): 6223


Problem DescriptionToday 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.
 
InputThe 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 (! = B), that means friend A and friend B know each other. There will be a blank line between two cases.
 
OutputFor 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
 
AuthorIgnatius. L classic query set is not much to explain. It seems that the last statement about empty rows is quite difficult.
#include<iostream>#include<cstdio>using namespace std;int gx[1005];int ans;int find(int x){    while(x!=gx[x])    x=gx[x];    return x;}void hb(int x,int y){    int i;    int rootx=find(x);    int rooty=find(y);    if(rootx!=rooty)        gx[rooty]=rootx;//for(i=1;i<=n;i++)cout<<gx[i]<<" ";}int main(){    int i,j,t,n,m,a,b;    cin>>t;    while(t--)    {        cin>>n>>m;        for(i=1;i<=n;i++)            gx[i]=i;               for(i=0;i<m;i++)            {                cin>>a>>b;                 hb(a,b);            }             ans=0;            for(i=1;i<=n;i++)               {                   if(gx[i]==i)                    ans++;               }             cout<<ans<<endl;    }    return 0;}



The younger brother wants to know that those questions on hang Dian hdu are only checked and checked. I want to train cainiao. I hope it is best to list the general difficulty levels. Thank you.

List all I know ..
Simple and query set
1213 How Many Tables
1232 smooth Engineering
(Hangdian does not have many simple query sets)

Simple minimal spanning tree
1233 or smooth Engineering
1863 smooth Engineering
1874 smooth project resumption
1875 continue smooth Engineering
1162 Eddy's picture
1102 Constructing Roads
1301 Jungle roanalyticdb
(You can use the minimum spanning tree function to perform exercises and query sets)

A little difficult and query set
1272 xiaoxi's maze
1325 Is It A Tree?
1856 More is better

Difficult to query
1116 Play on Words
1829A Bug's Life
1198 Farm Irrigation
3635 Dragon bils
2473Junk-Mail Filter
3172 Virtual Friends
3047 Zjnu Stadium
3038How Many Answers Are Wrong
1558 Segment set
1598 find the most comfortable road
3461 Code Lock
2818 Building Block
3367 false
3234Exclusive-OR

I forgot to spend some time searching for the HDOJ 1213 questions. Thank you very much.

What is this question?
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.