• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2011年5月>
            24252627282930
            1234567
            891011121314
            15161718192021
            22232425262728
            2930311234

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            HDOJ HDU 1856 More is better ACM 1856 IN HDU

            Posted on 2010-08-10 15:03 MiYu 閱讀(451) 評論(0)  編輯 收藏 引用 所屬分類: ACM ( 并查集 )
            MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋

            題目地址:
                     http://acm.hdu.edu.cn/showproblem.php?pid=1856
            題目描述:
            More is better

            Time Limit: 
            5000/1000 MS (Java/Others)    Memory Limit: 327680/102400 K (Java/Others)
            Total Submission(s): 
            1710    Accepted Submission(s): 643


            Problem Description
            Mr Wang wants some boys to help him with a project. Because the project 
            is rather complex, the more boys come, the better it will be. Of course there are certain requirements.

            Mr Wang selected a room big enough to hold the boys. The boy who are not been chosen has to leave the room immediately. There are 
            10000000 boys in the room numbered from 1 to 10000000 at the very beginning. After Mr Wang's selection any two of them who are still in this room should be friends (direct or indirect), or there is only one boy left. Given all the direct friend-pairs, you should decide the best way.
             

            Input
            The first line of the input contains an integer n (
            0 ≤ n ≤ 100 000- the number of direct friend-pairs. The following n lines each contains a pair of numbers A and B separated by a single space that suggests A and B are direct friends. (A ≠ B, 1 ≤ A, B ≤ 10000000)
             

            Output
            The output 
            in one line contains exactly one integer equals to the maximum number of boys Mr Wang may keep. 
             

            Sample Input
            4
            1 2
            3 4
            5 6
            1 6
            4
            1 2
            3 4
            5 6
            7 8
             

            Sample Output
            4
            2

            題目分析:
            如果對并查集比較熟習的話, 這道題就可以直接模板AC了.  不了解的話請點擊 :    并查集 學習 詳解
            這道題目的意思就是在 所有選出的集合中選出最大的集合, 也就是人最多的集合,  另外, 如果所有點
            都是孤立點, 也就是說所有人都互不認識, 那么 答案顯然是 1 了.

            代碼如下 :
            MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋

            #include 
            <iostream>
            using namespace std;
            typedef 
            struct {
                 
            int parent;
                 
            int cnt;   
            }Tset;  
            int maxSet = 0;
            typedef 
            struct treeUFS{
                   
            public:
                          treeUFS(
            int n = 0):N(n+1) { set = new Tset[N]; 
                                                      
            for ( int i = 0; i != N; ++ i) 
                                                      
            set[i].parent = i,set[i].cnt = 1
                                                    }
                          
            ~treeUFS(){ delete [] set; };
                          
            int find ( int x ){ int r = x; while ( set[r].parent != r ) 
                                                                r 
            = set[r].parent;       
                                                         
            int i = x;
                                                         
            while ( i != r) {   
                                                             
            int j = set[i].parent;
                                                             
            set[i].parent = r;
                                                             i 
            = j;
                                                         } 
                                               
            return r;
                                            }
                          
            void init () { for ( int i = 0; i != N; ++ i) set[i].parent = i,set[i].cnt = 1;  }               
                          
            void Merge( int x,int y ){  x = find ( x );  y = find ( y );  
                                                       
            if ( x == y ) return;
                                                       
            if ( set[x].cnt > set[y].cnt ){
                                                            
            set[y].parent = x;
                                                            
            set[x].cnt += set[y].cnt;
                                                            
            if ( set[x].cnt > maxSet ){
                                                                 maxSet 
            = set[x].cnt ;
                                                                 }
                                                       }
                                                       
            else{
                                                               
            set[x].parent = y;
                                                               
            set[y].cnt += set[x].cnt;
                                                               
            if ( set[y].cnt > maxSet ){
                                                                    maxSet 
            = set[y].cnt ;
                                                                    }        
                                                           }      
                                                    }
                          
            int getSetCount ( int x ){ return set[ find(x) ].cnt; }
                   
            private:
                          Tset 
            *set;
                          
            int N;         
            }treeUFS; 
            int main ()
            {
                
            int N,a,b;
                treeUFS UFS ( 
            10000000 );
                
            while ( scanf ( "%d"&N ) != EOF )
                {
                        maxSet 
            = 0
                        
            for ( int i = 1; i <= N; ++ i )
                        {
                              scanf ( 
            "%d%d"&a,&b );
                              UFS.Merge ( a,b ); 
                        }           
                        printf ( maxSet 
            == 0 ? "1\n" : "%d\n",maxSet );
                        UFS.init ();
                }
                
            return 0
            }
            久久久久久久99精品免费观看| 中文字幕久久久久人妻| 久久久久久九九99精品| 中文字幕乱码人妻无码久久| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 国产韩国精品一区二区三区久久| 国产精品美女久久久久网| 亚洲国产天堂久久综合网站| 看全色黄大色大片免费久久久| 久久91精品综合国产首页| 色婷婷综合久久久久中文一区二区 | 亚洲国产精品久久久久久| 香蕉久久影院| 久久精品国产久精国产| 久久婷婷五月综合成人D啪| 青青青青久久精品国产| 亚洲va久久久噜噜噜久久狠狠| 久久精品国产免费| 亚洲国产精品成人久久| 一本大道久久香蕉成人网| 国产精品久久久久aaaa| 亚洲综合熟女久久久30p| 99久久国产主播综合精品| 国产精品美女久久久久| 香蕉久久夜色精品国产2020| 国产精品禁18久久久夂久| 99久久国产亚洲综合精品| 久久国产精品国产自线拍免费 | 久久精品国产亚洲AV电影| 精品一久久香蕉国产线看播放| 久久ZYZ资源站无码中文动漫 | 国产精品一区二区久久精品涩爱| 久久成人精品视频| 99久久这里只有精品| 97久久超碰国产精品旧版| 男女久久久国产一区二区三区| 一本一道久久a久久精品综合| 久久亚洲国产精品123区| 久久免费高清视频| 久久国产免费观看精品| 久久99精品久久久久久久不卡|