• <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 - 195,  comments - 30,  trackbacks - 0
            #include<iostream>
            using namespace std;

            #define mx 2000

            struct

            {

                   
            int rank;

                   
            int parent;

                   
            int opposite;   //與自己不同性的某一蟲子,初始化時(shí)為自己 

            }bugs[mx];

            void Make_set(int n);

            int Find_set(int x);

            void Union(int x,int y);

            int main()

            {

                 
            int ts;//測(cè)試數(shù)據(jù)的數(shù)量 

                 scanf(
            "%d",&ts);

                 
            int t=1;

                 
            while(ts--)

                 {

                   
            int bugnum/*蟲子數(shù)*/,pairs/*研究的對(duì)數(shù)*/;

                   scanf(
            "%d%d",&bugnum,&pairs);

                   Make_set(bugnum);

                   
            int i;

                   
            int m,f;

                   
            bool IsFound=false;

                   
            int a,b;

                   
            for(i=0;i<pairs;i++)

                   {

                       scanf(
            "%d%d",&m,&f);//m號(hào)蟲,f號(hào)蟲 

                       a
            =Find_set(m-1);

                       b
            =Find_set(f-1);

                       
            if(a==b)//兩只蟲在同一集合中則有同性戀蟲的懷疑 

                         IsFound
            =true;

                       
            if(bugs[m-1].opposite!=m-1)//如果opposite中不是自己,則union(b,bugs[m-1].opposite 

                         Union(b
            /*f-1*/,bugs[m-1].opposite);

                       
            else//如果opposite是自己(既未被設(shè)置),則設(shè)為對(duì)方。 

                         bugs[m
            -1].opposite=b;//f-1;

                       
            if(bugs[f-1].opposite!=f-1)//同理 

                         Union(a
            /*m-1*/,bugs[f-1].opposite);

                       
            else

                         bugs[f
            -1].opposite=a;//m-1;

                   }

                   
            if(IsFound)

                     printf(
            "Scenario #%d:\nSuspicious bugs found!\n\n",t++);

                   
            else

                     printf(
            "Scenario #%d:\nNo suspicious bugs found!\n\n",t++);

                 }

                 
            //system("pause");

                 
            return 0;

            }

            void Make_set(int n)   //初始化,產(chǎn)生n個(gè)集合,每個(gè)集合一只蟲 

            {

                 
            int i;

                 
            for(i=0;i<n;i++)

                 {

                     bugs[i].rank
            =0;

                     bugs[i].parent
            =i;

                     bugs[i].opposite
            =i;

                 }

            }

            int Find_set(int x)   //尋找根節(jié)點(diǎn),路徑壓縮 

            {

                 
            if(x!=bugs[x].parent)

                   bugs[x].parent
            =Find_set(bugs[x].parent);

                 
            return bugs[x].parent;

            }

            void Union(int x,int y)     //合并相同集合,按秩合并 

            {

                 
            int a=Find_set(x);

                 
            int b=Find_set(y);

                 
            if(bugs[a].rank>bugs[b].rank)

                     bugs[b].parent
            =a;

                 
            else

                     bugs[a].parent
            =b;

                 
            if(bugs[x].rank==bugs[y].rank)

                   bugs[y].rank
            ++;

            }
            posted on 2009-06-30 15:43 luis 閱讀(199) 評(píng)論(0)  編輯 收藏 引用

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


            <2011年11月>
            303112345
            6789101112
            13141516171819
            20212223242526
            27282930123
            45678910

            常用鏈接

            留言簿(3)

            隨筆分類

            隨筆檔案

            文章分類

            文章檔案

            友情鏈接

            搜索

            •  

            最新評(píng)論

            閱讀排行榜

            評(píng)論排行榜

            久久婷婷午色综合夜啪| 久久天天躁狠狠躁夜夜2020| 国产精品久久久99| 久久精品无码专区免费| 亚洲欧美一级久久精品| 人妻精品久久久久中文字幕69| 久久久婷婷五月亚洲97号色| 国产激情久久久久影院小草| 精品国产91久久久久久久| 久久精品成人欧美大片| 国产三级观看久久| 日批日出水久久亚洲精品tv| 99久久99久久精品免费看蜜桃| 午夜肉伦伦影院久久精品免费看国产一区二区三区 | 久久精品国产99国产精品| 久久精品国产72国产精福利| 久久国产亚洲精品| 久久精品无码专区免费东京热 | 久久久久久久波多野结衣高潮 | 国产精品久久国产精麻豆99网站 | 久久婷婷五月综合97色直播| 欧洲精品久久久av无码电影| 久久99中文字幕久久| 久久久久亚洲爆乳少妇无| 亚洲午夜久久久久妓女影院| 久久亚洲中文字幕精品一区四 | 久久伊人五月丁香狠狠色| 国产亚州精品女人久久久久久| 无码人妻少妇久久中文字幕蜜桃| 久久99精品久久久久久秒播| 久久久久亚洲AV无码专区首JN| 色妞色综合久久夜夜| 久久精品一区二区影院| 亚洲国产欧美国产综合久久| 99久久亚洲综合精品成人| AV色综合久久天堂AV色综合在| 狠狠色综合网站久久久久久久高清| 久久精品国产亚洲AV麻豆网站| 欧美成a人片免费看久久| 丰满少妇高潮惨叫久久久| 亚洲精品乱码久久久久久不卡|