• <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 閱讀(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 }
            久久精品国产亚洲AV大全| 97精品伊人久久久大香线蕉| 69国产成人综合久久精品| 丁香五月网久久综合| 久久精品国产一区二区| 伊人久久大香线蕉av不变影院| 国产精品久久久亚洲| 四虎国产精品成人免费久久| 久久婷婷国产综合精品| 亚洲伊人久久综合影院| 国内精品久久久久久不卡影院| 精品国产日韩久久亚洲| 爱做久久久久久| 久久无码人妻一区二区三区 | 亚洲精品国产字幕久久不卡| 精品一区二区久久| 国产毛片欧美毛片久久久| 久久精品无码一区二区日韩AV| 国产午夜免费高清久久影院| 一本色道久久综合狠狠躁| 久久综合久久鬼色| 91精品国产91久久久久久蜜臀| 欧美黑人又粗又大久久久| 亚洲欧美国产日韩综合久久| 国产午夜精品久久久久九九| 久久久青草久久久青草| 99精品国产在热久久无毒不卡 | 久久伊人精品青青草原日本| 99久久777色| 国产精品久久久久9999高清| 久久99热只有频精品8| 久久精品亚洲中文字幕无码麻豆 | 区亚洲欧美一级久久精品亚洲精品成人网久久久久 | 久久青青草原亚洲av无码| 国产精品一区二区久久精品无码| 热re99久久6国产精品免费| 2021国产精品久久精品| 人妻无码αv中文字幕久久琪琪布 人妻无码精品久久亚瑟影视 | 久久99热这里只频精品6| 色青青草原桃花久久综合| 亚洲国产精品综合久久一线|