• <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>

            我希望你是我獨家記憶

            一段永遠封存的記憶,隨風而去
            posts - 263, comments - 31, trackbacks - 0, articles - 3
               :: 首頁 :: 新隨筆 ::  :: 聚合  :: 管理

            H1856——并查集

            Posted on 2008-09-04 18:31 Hero 閱讀(136) 評論(0)  編輯 收藏 引用 所屬分類: 代碼如詩--ACM
             1 //Accepted 1856 312MS 39024K 979 B C++ HDU
             2 
             3 //并查集
             4 
             5 #include <stdio.h>
             6 #include <stdlib.h>
             7 #include <string.h>
             8 
             9 const int size = 10000010 ;
            10 int father[size] ;
            11 
            12 int inn ;
            13 
            14 int Find( int x )
            15 {
            16     if( father[x] < 0 ) return x ;
            17 
            18     int fx = Find( father[x] ) ; father[x] = fx ;
            19 
            20     return fx ;
            21 }
            22 
            23 void Union( int a, int b ) 
            24 {
            25     int fa = Find( a ) ; int fb = Find( b ) ;
            26 
            27     if( fa != fb )
            28     {
            29         if( father[fa] <= father[fb] )
            30         {
            31             father[fa] += father[fb] ; father[fb] = fa ;
            32         }
            33         else
            34         {
            35             father[fb] += father[fa] ; father[fa] = fb ;
            36         }
            37     }
            38 }
            39 
            40 void input()
            41 {
            42     forint i=0; i<size; i++ ) father[i] = -1 ;
            43 
            44     int a, b ; int fa, fb ;
            45     forint i=1; i<=inn; i++ )
            46     {
            47         scanf( "%d %d"&a, &b ) ; Union( a, b ) ;
            48     }
            49 }
            50 
            51 void output() 
            52 {
            53     int out = size ;
            54     forint i=1; i<size; i++ ) ifout > father[i] ) out = father[i] ;
            55 
            56     printf( "%d\n"-1*out ) ;
            57 }
            58 
            59 int main()
            60 {
            61     while( scanf( "%d"&inn ) != EOF )
            62     {
            63         input() ;
            64 
            65         //process() ;
            66 
            67         output() ;
            68     }
            69 
            70     return 0 ;
            71 }
            99久久无码一区人妻a黑| 亚洲?V乱码久久精品蜜桃| 一级做a爰片久久毛片看看| 久久久久18| 精品免费久久久久久久| 成人资源影音先锋久久资源网| 午夜精品久久久久久| 国产69精品久久久久9999APGF| 国内精品人妻无码久久久影院| 国产精品99久久久久久人| 久久99精品久久久久久噜噜| 久久久久无码精品国产| 亚洲精品tv久久久久| 无码国内精品久久人妻| 伊人久久综合精品无码AV专区| 久久久久久狠狠丁香| 国产精品久久久久jk制服| 成人国内精品久久久久影院VR| 久久超乳爆乳中文字幕| 国产免费久久精品丫丫| 久久天天躁狠狠躁夜夜avapp| 伊人久久大香线蕉亚洲五月天 | 久久99精品国产麻豆蜜芽| 色综合久久无码五十路人妻 | 久久久久久久女国产乱让韩| 亚洲欧洲精品成人久久曰影片| 99久久精品午夜一区二区| 欧美日韩精品久久久久| 久久婷婷五月综合97色直播 | 久久精品国产亚洲麻豆| 999久久久无码国产精品| 久久天天躁夜夜躁狠狠| 久久综合伊人77777| 香蕉99久久国产综合精品宅男自 | 久久精品成人| 精品综合久久久久久97超人 | 国产69精品久久久久9999APGF| 亚洲欧美一级久久精品| 青青热久久国产久精品 | 久久亚洲天堂| 亚洲欧洲久久av|