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

            ACM___________________________

            ______________白白の屋
            posts - 182, comments - 102, trackbacks - 0, articles - 0
            <2010年10月>
            262728293012
            3456789
            10111213141516
            17181920212223
            24252627282930
            31123456

            常用鏈接

            留言簿(24)

            隨筆分類(332)

            隨筆檔案(182)

            FRIENDS

            搜索

            積分與排名

            最新隨筆

            最新評論

            閱讀排行榜

            評論排行榜

            MiYu原創, 轉帖請注明 : 轉載自 ______________白白の屋    

             

            題目地址:

            http://poj.org/problem?id=1258

            題目描述:

            Agri-Net
            Time Limit: 1000MSMemory Limit: 10000K
            Total Submissions: 16557Accepted: 6745

            Description

            Farmer John has been elected mayor of his town! One of his campaign promises was to bring internet connectivity to all farms in the area. He needs your help, of course. 
            Farmer John ordered a high speed connection for his farm and is going to share his connectivity with the other farmers. To minimize cost, he wants to lay the minimum amount of optical fiber to connect his farm to all the other farms. 
            Given a list of how much fiber it takes to connect each pair of farms, you must find the minimum amount of fiber needed to connect them all together. Each farm must connect to some other farm such that a packet can flow from any one farm to any other farm. 
            The distance between any two farms will not exceed 100,000. 

            Input

            The input includes several cases. For each case, the first line contains the number of farms, N (3 <= N <= 100). The following lines contain the N x N conectivity matrix, where each element shows the distance from on farm to another. Logically, they are N lines of N space-separated integers. Physically, they are limited in length to 80 characters, so some lines continue onto others. Of course, the diagonal will be 0, since the distance from farm i to itself is not interesting for this problem.

            Output

            For each case, output a single integer length that is the sum of the minimum length of fiber required to connect the entire set of farms.

            Sample Input

            4
            0 4 9 21
            4 0 8 17
            9 8 0 16
            21 17 16 0
            

            Sample Output

            28

            題目分析 :
             	MST 水題, 用KRUSKARL 或 PRIM 輕松能過.
            代碼如下 :
            /*
            Mail to   : miyubai@gamil.com
            MyBlog    : http://baiyun.me
            Link      : http://www.cnblogs.com/MiYu  || http://www.shnenglu.com/MiYu
            Author By : MiYu
            Test      : 1
            Complier  : g++ mingw32-3.4.2
            Program   : Agri-Net
            Doc Name  : PKU_1258
            */
            //#pragma warning( disable:4789 )
            #include <iostream>
            #include <fstream>
            #include <sstream>
            #include <algorithm>
            #include <string>
            #include <set>
            #include <map>
            #include <utility>
            #include <queue>
            #include <stack>
            #include <list>
            #include <vector>
            #include <cstdio>
            #include <cstdlib>
            #include <cstring>
            #include <cmath>
            #include <ctime>
            using namespace std;
            const int MAX = 105;
            int st[105];
            int N, x, y, w;
            struct vv {
                   int x, y, val;
                   void set ( int a, int b, int w ) { x=a,y=b,val=w; }
            
            }v[10005];       
            bool cmp ( const vv &a, const vv &b ) {
                      return a.val < b.val;     
            }
            void creat () {
                 for ( int i = 0; i <= N; ++ i )
                      st[i] = i;     
            }
            int find ( int x ) {
                return x != st[x] ? find ( st[x] ) : x;    
            }
            void merge ( int x, int y ) {
                 x = find ( x );
                 y = find ( y );
                 if ( x == y ) return;
                 st[y] = x;     
            }
            int main ()
            {
                while ( scanf ( "%d", &N )==1) {
                       creat ();
                       memset ( v, 0, sizeof ( v ) );
                       int c = 0;
                       for ( int i = 1; i <= N; ++ i ) {
                            for ( int j = 1; j <= N; ++ j ) {
                                 scanf ( "%d", &w );  
                                 v[c++].set ( i,j,w );  
                            }    
                       }     
                       sort ( v, v + c, cmp );
                       int sum = 0;
                       for ( int i = 0 ; i < c; ++ i ) {
                            if ( find ( v[i].x ) != find ( v[i].y ) ) {
                                sum += v[i].val;  
                                merge ( v[i].x, v[i].y );
                            }    
                       }
                       printf ( "%d\n", sum );
                }
                return 0;
            }
            

             

            中文字幕无码精品亚洲资源网久久| 亚洲∧v久久久无码精品| 亚洲天堂久久精品| 久久久综合香蕉尹人综合网| 伊人久久大香线蕉综合Av| 久久久精品午夜免费不卡| 色妞色综合久久夜夜| 国产精品天天影视久久综合网| 欧美粉嫩小泬久久久久久久| 国产V综合V亚洲欧美久久| 无码任你躁久久久久久| 99久久免费国产特黄| 精品久久久无码21p发布| 精品无码人妻久久久久久| 久久精品水蜜桃av综合天堂| 人妻中文久久久久| 国产精品18久久久久久vr| 亚洲日韩中文无码久久| 久久久99精品一区二区| 久久99免费视频| 久久精品国产亚洲av日韩| yy6080久久| 一本久久综合亚洲鲁鲁五月天| 久久无码av三级| 狠狠色丁香久久综合婷婷| 久久精品aⅴ无码中文字字幕重口 久久精品a亚洲国产v高清不卡 | 国内精品久久久久影院亚洲| 国产成人久久精品二区三区| 国产欧美久久一区二区| 天堂久久天堂AV色综合| 亚洲女久久久噜噜噜熟女| 亚洲人成伊人成综合网久久久| 亚洲国产精品成人AV无码久久综合影院 | 青青草国产精品久久久久| AV无码久久久久不卡网站下载| 国产A三级久久精品| 久久伊人五月丁香狠狠色| 中文字幕无码精品亚洲资源网久久| 亚洲午夜无码AV毛片久久| 久久综合视频网| 精品综合久久久久久97|