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

            pku 2524

            2009年7月12日 星期日

            題目鏈接:PKU  2524  Ubiquitous  Religions

            分類:最基本的并查集

            Code:

             1
            #include<stdio.h>
             2#define MAXN 50005
             3int parent[MAXN],count;
             4void init(int n)
             5{
             6    int i;
             7    for(i=1;i<=n;i++)parent[i]=-1;
             8}

             9
            10int find(int x)
            11{
            12    if(parent[x]<0return x;
            13    else return parent[x]=find(parent[x]);
            14}

            15
            16int Union(int x,int y)
            17{
            18    int root1=find(x),root2=find(y);
            19    if(root1==root2) return root1;
            20    count--;
            21    if(parent[root1]<parent[root2])
            22    {
            23        parent[root1]+=parent[root2];
            24        parent[root2]=root1;
            25        return root1;
            26    }

            27    else
            28    {
            29        parent[root2]+=parent[root1];
            30        parent[root1]=root2;
            31        return root2;
            32    }

            33    
            34}

            35int main()
            36{
            37    int n,m,i,a,b,ccase=1;
            38    while(scanf("%d%d",&n,&m)!=EOF)
            39    {
            40        if(!m&&!n)break;
            41        init(n);
            42        count=n;
            43        for(i=0;i<m;i++)
            44        {
            45            scanf("%d%d",&a,&b);
            46            Union(a,b);
            47        }

            48        printf("Case %d: %d\n",ccase++,count);
            49
            50    }

            51    return 0;
            52}

            53




            posted on 2009-07-12 23:44 蝸牛也Coding 閱讀(740) 評論(0)  編輯 收藏 引用

            <2009年9月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            導航

            統計

            常用鏈接

            留言簿(8)

            隨筆檔案(78)

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            久久精品国产亚洲AV无码偷窥| 久久国产乱子伦免费精品| 91精品国产综合久久精品| 久久亚洲中文字幕精品有坂深雪 | 久久久久久毛片免费看| 久久精品国产99久久丝袜| 欧美精品九九99久久在观看| av色综合久久天堂av色综合在| 99久久99久久久精品齐齐| 久久精品嫩草影院| 久久婷婷是五月综合色狠狠| 国产精品一区二区久久| 欧美伊人久久大香线蕉综合69| 久久精品国产清高在天天线| 久久久久久久综合综合狠狠| 国产精品久久久天天影视| 亚洲国产视频久久| 国产精品久久久天天影视香蕉| 国产色综合久久无码有码| 国产精品VIDEOSSEX久久发布| 亚洲精品乱码久久久久久蜜桃图片| 久久精品免费观看| 国产aⅴ激情无码久久| 久久久WWW成人| 国产精品美女久久久久网| 久久精品成人欧美大片| 久久亚洲天堂| 久久久WWW成人| 精品久久人人爽天天玩人人妻| 97久久超碰国产精品旧版 | 国产精品久久久久久五月尺| 热久久这里只有精品| 久久亚洲美女精品国产精品| 久久人妻AV中文字幕| 久久国产AVJUST麻豆| 色婷婷久久综合中文久久一本| 狠狠久久综合| 国产精品欧美久久久久无广告| 热久久这里只有精品| 国产国产成人精品久久| 久久91亚洲人成电影网站|