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

            我希望你是我獨(dú)家記憶

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

            H1856——并查集

            Posted on 2008-09-04 18:31 Hero 閱讀(135) 評論(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国产一区二区三区| 国内高清久久久久久| 久久水蜜桃亚洲av无码精品麻豆| 久久精品国产亚洲AV无码娇色| 日本福利片国产午夜久久| 一本一本久久a久久精品综合麻豆| 少妇高潮惨叫久久久久久| 99久久国产综合精品五月天喷水| 欧美亚洲国产精品久久| 国产精品99久久免费观看| 久久亚洲精品国产精品婷婷| 亚洲国产一成久久精品国产成人综合| 亚洲精品蜜桃久久久久久| 国产亚州精品女人久久久久久 | 国产69精品久久久久APP下载| 久久婷婷色综合一区二区| 伊人热人久久中文字幕| 亚洲中文久久精品无码| 久久无码精品一区二区三区| 精品无码久久久久久尤物| 欧美一区二区久久精品| 久久精品亚洲男人的天堂| www久久久天天com| 蜜臀av性久久久久蜜臀aⅴ麻豆| 午夜精品久久影院蜜桃| 久久精品视频91| 99热热久久这里只有精品68| 99久久久国产精品免费无卡顿| 久久无码中文字幕东京热| 久久婷婷色综合一区二区| 久久精品亚洲精品国产欧美| 久久99国产一区二区三区| 久久久91人妻无码精品蜜桃HD| 91亚洲国产成人久久精品| 午夜不卡888久久| 久久精品国产只有精品2020| 久久精品国产免费| 韩国三级中文字幕hd久久精品 | 伊人久久免费视频| 91精品国产91热久久久久福利|