• <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 閱讀(741) 評論(0)  編輯 收藏 引用

            <2009年7月>
            2829301234
            567891011
            12131415161718
            19202122232425
            2627282930311
            2345678

            導航

            統計

            常用鏈接

            留言簿(8)

            隨筆檔案(78)

            搜索

            積分與排名

            最新評論

            閱讀排行榜

            評論排行榜

            麻豆精品久久精品色综合| 成人国内精品久久久久影院| 日韩精品久久久久久| 国产午夜精品久久久久九九| 久久久噜噜噜久久中文字幕色伊伊| 久久这里只有精品视频99| 久久精品亚洲AV久久久无码| 久久人人爽人人爽人人片AV不| 久久国产一区二区| 久久精品国产亚洲AV久| 国产成人久久AV免费| 欧美久久一区二区三区| 精品久久久久久久无码| 国产亚州精品女人久久久久久 | 国内精品久久久久影院老司| 亚洲精品乱码久久久久久蜜桃图片| 国内精品久久九九国产精品| yy6080久久| 日韩电影久久久被窝网| 伊人色综合久久天天| 亚洲精品午夜国产VA久久成人| 精品无码久久久久久久久久| 久久国产乱子伦免费精品| 伊人情人综合成人久久网小说| 亚洲国产天堂久久综合网站| 精品久久久久久无码专区| 亚洲欧美日韩中文久久| 久久久久波多野结衣高潮| 香蕉99久久国产综合精品宅男自| 精品国产91久久久久久久| 精品乱码久久久久久久| 中文字幕日本人妻久久久免费 | 久久一本综合| 国产香蕉97碰碰久久人人| 国内精品久久久久久久久| 久久亚洲国产午夜精品理论片| 国产成人精品久久二区二区 | 久久高潮一级毛片免费| 99久久精品免费| 精品国产91久久久久久久a | 久久伊人五月丁香狠狠色|