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

            Drolca

            Apologize To Drolca
            隨筆 - 28, 文章 - 1, 評論 - 6, 引用 - 0
            數(shù)據(jù)加載中……

            pku 2524 Ubiquitous Religions

            #include <iostream>
            using namespace std;

            const int maxn=50001;
            int father[maxn];
            int rank[maxn];
            void prepare(int n)
            {
                
            for(int i=1;i<=n;i++)
                
            {
                    father[i]
            =i;
                    rank[i]
            =i;
                }

            }

            int find(int x)
            {
                
            if(father[x]!=x)
                    father[x]
            =find(father[x]);
                
            return father[x];
            }

            void union_set(int x,int y)
            {
                
            int fx,fy;
                fx
            =find(x);
                fy
            =find(y);
                
            if(rank[fx]>rank[fy])
                    father[fy]
            =fx;
                
            else if(rank[fx]<rank[fy])
                    father[fx]
            =fy;
                
            else 
                
            {
                    father[fy]
            =fx;
                    rank[fx]
            ++;
                }

            }

            int main()
            {
                #ifndef ONLINE_JUDGE
                freopen(
            "in.txt","r",stdin) ;
                
            #endif
                
            int n,m,i;
                
            int casen=0;
                
            while(scanf("%d%d",&n,&m)!=EOF)
                
            {
                    casen
            ++;
                    
            if(n==0&&m==0break;
                    prepare(n);
                    
            int    sum=0;
                    
            for(i=1;i<=m;i++)
                    
            {
                        
            int x,y;
                        scanf(
            "%d%d",&x,&y);
                        union_set(x,y);
                    }

                    
            for(i=1;i<=n;i++)
                        
            if(father[i]==i) sum++;
                    printf(
            "Case %d: %d\n",casen,sum);
                }

                
            return 0;
            }

            posted on 2009-08-20 17:28 Drolca 閱讀(92) 評論(0)  編輯 收藏 引用


            只有注冊用戶登錄后才能發(fā)表評論。
            網(wǎng)站導(dǎo)航: 博客園   IT新聞   BlogJava   博問   Chat2DB   管理


            久久午夜夜伦鲁鲁片免费无码影视| 久久天天躁狠狠躁夜夜96流白浆| 国产精品熟女福利久久AV| 老司机国内精品久久久久| 久久九九久精品国产| 国内精品久久久久影院老司| 日产精品99久久久久久| 韩国三级中文字幕hd久久精品| 无夜精品久久久久久| 老色鬼久久亚洲AV综合| 久久996热精品xxxx| 中文字幕无码精品亚洲资源网久久| 久久ww精品w免费人成| 久久国产欧美日韩精品免费| 久久66热人妻偷产精品9| 热久久国产欧美一区二区精品| 亚洲成色www久久网站夜月 | 久久精品国产一区二区电影| 久久精品卫校国产小美女| 91秦先生久久久久久久| 日本久久久久亚洲中字幕| 日韩亚洲国产综合久久久| 91视频国产91久久久| 亚洲国产欧美国产综合久久| 久久久人妻精品无码一区| 伊人色综合久久天天| 久久久久人妻一区精品性色av| 欧美精品一区二区久久 | 久久激情五月丁香伊人| 色狠狠久久AV五月综合| 伊人久久亚洲综合影院| 久久久久成人精品无码| 国内精品久久久久久不卡影院 | 久久97久久97精品免视看秋霞| 久久精品成人影院| 亚洲中文字幕久久精品无码APP| 久久国产视频网| 国产成人久久精品麻豆一区| 精品熟女少妇aⅴ免费久久| 久久精品女人天堂AV麻| 欧美久久久久久精选9999|