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

            C小加

            厚德 博學 求真 至善 The bright moon and breeze
            posts - 145, comments - 195, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            poj 1251 NYOJ 434 Jungle Roads 解題報告

            Posted on 2011-11-05 19:44 C小加 閱讀(1351) 評論(0)  編輯 收藏 引用 所屬分類: 解題報告
            題意:在相通n個島嶼的所有橋都壞了,要重修,重修每一個橋所用的時間不同,求重修使每個島嶼都間接或直接與其他島嶼相同時所用的的最短時間(只有修完一個橋后才可修下一個橋)。
            思路:10月份月賽唯一過的題。裸體的最小生成樹,我用的是Kruskal+并查集。
             
            #include 
            <iostream>
            #include 
            <algorithm>
            #include 
            <cstdio>
            #include 
            <cstring>
            using namespace std;
            const int MAX=27*27+1;
            typedef 
            struct
            {
                
            int a,b;
                
            int len;
            }node;

            node nod[MAX];
            int father[MAX];

            int cmp(node b1,node b2)
            {
                
            return b1.len<b2.len;
            }
            int find(int x)
            {
                
            return father[x]==x?x:father[x]=find(father[x]);
            }
            void Union(int a1,int a2)
            {
                father[a1]
            =a2;
            }
            int main()
            {
                
            int n;
                
            while(cin>>n&&n)
                {
                    memset(nod,
            0,sizeof(nod));
                    
            int i;
                    
            for(i=0;i<=MAX;i++)
                    {
                        father[i]
            =i;
                    }
                    
            int tempn=n,cnt=0;
                    tempn
            --;
                    
            while(tempn--)
                    {
                        
            string s1;
                        cin
            >>s1;
                        
            int qn;
                        cin
            >>qn;
                        
            if(qn==0continue;
                        
            while(qn--)
                        {
                            
            string s2;
                            cin
            >>s2;
                            
            int len;
                            cin
            >>len;
                            nod[cnt].a
            =s1[0]-'A'+1;
                            nod[cnt].b
            =s2[0]-'A'+1;
                            nod[cnt].len
            =len;
                            cnt
            ++;
                        }
                    }
                    sort(nod,nod
            +cnt,cmp);
                    
            int sum=0;
                    
            for(i=0;i<cnt;i++)
                    {
                        
            int x=find(nod[i].a);
                        
            int y=find(nod[i].b);
                        
            if(x==y)
                        
            continue;
                        
            else
                        {
                            Union(x,y);
                            sum
            +=nod[i].len;
                        }
                    }
                    cout
            <<sum<<endl;

                }
                
            return 0;
            }
                    

            a级毛片无码兔费真人久久| 久久毛片一区二区| 91久久精品国产成人久久| 久久久久久综合一区中文字幕 | 新狼窝色AV性久久久久久| 久久国产精品成人影院| 国产精品无码久久四虎| 欧美丰满熟妇BBB久久久| 九九久久精品无码专区| 久久精品人成免费| 久久久久久久91精品免费观看| 国内精品人妻无码久久久影院| 欧美日韩中文字幕久久久不卡 | 精品久久久久久无码免费| 亚洲精品无码久久久久| 久久精品二区| 久久综合丁香激情久久| 91精品国产色综合久久| 久久久久免费精品国产| 久久91这里精品国产2020| 久久国产乱子伦免费精品| 国产成人精品综合久久久久| 久久国产午夜精品一区二区三区| 精品久久久久中文字幕日本| 青青草原综合久久大伊人| 久久午夜无码鲁丝片午夜精品| 精品久久久久久中文字幕| AV色综合久久天堂AV色综合在| 久久人人爽人人人人爽AV| 久久中文字幕人妻熟av女| 久久久久噜噜噜亚洲熟女综合| 2021国产成人精品久久| 色综合色天天久久婷婷基地| 亚洲国产精品久久久久网站| 久久精品国产69国产精品亚洲| www.久久热.com| 精品国产一区二区三区久久久狼 | 久久精品视频网| 久久96国产精品久久久| 91亚洲国产成人久久精品网址| 国产午夜精品理论片久久 |