• <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
               :: 首頁(yè) :: 新隨筆 ::  :: 聚合  :: 管理

            H1856——并查集

            Posted on 2008-09-04 18:31 Hero 閱讀(138) 評(píng)論(0)  編輯 收藏 引用 所屬分類: 代碼如詩(shī)--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 }
            国产精品久久久久久久久| 亚洲欧美国产精品专区久久 | 伊人色综合久久天天网| 久久综合亚洲色HEZYO社区| 久久影院综合精品| 精品免费久久久久国产一区| 亚洲国产精品一区二区三区久久| 亚洲精品乱码久久久久久按摩| 久久亚洲综合色一区二区三区| 久久夜色精品国产www| 久久亚洲私人国产精品| 久久精品国产99久久丝袜| 久久综合88熟人妻| 亚洲日本va午夜中文字幕久久| 国产精品久久久久久久| 精产国品久久一二三产区区别| 久久免费小视频| 久久99精品国产自在现线小黄鸭| 久久精品国产亚洲5555| 久久发布国产伦子伦精品| 久久人人爽人人爽人人片av麻烦| 久久国产精品99精品国产987| 久久久久久久波多野结衣高潮| 亚洲国产成人久久精品影视 | 亚洲日本久久久午夜精品| 免费观看成人久久网免费观看| 久久男人Av资源网站无码软件| 伊人久久大香线蕉AV一区二区 | 亚洲国产欧美国产综合久久| 日韩va亚洲va欧美va久久| 国产精品永久久久久久久久久| 99久久中文字幕| 91精品国产9l久久久久| 久久久久久久久无码精品亚洲日韩| 久久AV高潮AV无码AV| 久久久久久精品免费免费自慰| 亚洲?V乱码久久精品蜜桃| 亚洲AV伊人久久青青草原| 久久久这里有精品| 久久AV高潮AV无码AV| 婷婷综合久久中文字幕蜜桃三电影|