hdu 1213 How Many Tables,hdu1213

來源:互聯網
上載者: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(A!=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經典並查集不多做解釋  感覺最後一句關於空行的說法比較坑
#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;}



小弟想知道杭電 hdu上那些題目是只考察並查集的,菜鳥我想練練,希望最好可以把大概難易程度列出謝了

把我知道的都列出來了。。
簡單並查集
1213 How Many Tables
1232 暢通工程
(杭電簡單的並查集不是很多)

簡單最小產生樹
1233 還是暢通工程
1863 暢通工程
1874 暢通工程再續
1875 繼續暢通工程
1162 Eddy's picture
1102 Constructing Roads
1301 Jungle Roads
(可以通過最小產生樹練習並查集)

稍微有點難度並查集
1272 小希的迷宮
1325 Is It A Tree?
1856 More is better

有點難度的並查集
1116Play on Words
1829A Bug's Life
1198Farm Irrigation
3635Dragon Balls
2473Junk-Mail Filter
3172Virtual Friends
3047Zjnu Stadium
3038How Many Answers Are Wrong
1558Segment set
1598find the most comfortable road
3461Code Lock
2818Building Block
3367Pseudoforest
3234Exclusive-OR
 
HDOJ 1213題,忘花費點時間給找錯 萬分感謝

這是什麼題目?
 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.