<output id="qn6qe"></output>

    1. <output id="qn6qe"><tt id="qn6qe"></tt></output>
    2. <strike id="qn6qe"></strike>

      亚洲 日本 欧洲 欧美 视频,日韩中文字幕有码av,一本一道av中文字幕无码,国产线播放免费人成视频播放,人妻少妇偷人无码视频,日夜啪啪一区二区三区,国产尤物精品自在拍视频首页,久热这里只有精品12
      書山有徑勤為路>>>>>>>>

      <<<<<<<<學海無涯苦作舟!

      Kruskal算法解決POJ 1258

      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
       
       
      #include "iostream"
      #include "algorithm"
      using namespace std;
      structline
      {
      	int begin;
      	int end;
      	int length;
      };
      line Num[10001];
      int father[101], map[101][101], i, j, numofline, numofnode;
      int find(int k)
      {
      	return father[k]==k?k:father[k]=find(father[k]);
      }
      int cmp(line a, line b)
      {
      	return a.length<b.length;
      }
      int kruskal()
      {
      	int minlen = 0, a, b;
      	for(i=0; i<numofline; i++)
      	{
      		a = find(Num[i].begin);
      		b = find(Num[i].end);
      		if(a!=b)
      		{
      			father[a] = b;
      			minlen += Num[i].length;
      		}
      	}
      	return minlen;
      }
      void Init()
      {
      	int counter=0;
      	for(i=1; i<=numofnode; i++)  //這兩個數(shù)組要從1開始,在利于father數(shù)組的初始化,但同時要注意i<=numofnode,中的=號不要忘記了。
      	{
      		for(j=1; j<=numofnode; j++)  //注意這里是雙重循環(huán),所以Num結構體要開nodenum的平方倍。不然會出現(xiàn)Memory Limit Exceeded。
      		{
      			cin>>map[i][j];
      			if(i<j)
      			{
      				Num[counter].begin = i;
      				Num[counter].end = j;
                      Num[counter++].length = map[i][j];
      			}
      		}
      		father[i] = i;
      		numofline = counter;  //初始化nomofline.
      	}
      	sort(Num, Num+counter, cmp);
      }
      int main()
      {
      	while(cin>>numofnode)
      	{
      		Init();
      		cout<<kruskal()<<endl;
      	}
      }

      posted on 2011-09-23 20:55  More study needed.  閱讀(318)  評論(0)    收藏  舉報

      導航

      書山有徑勤為路>>>>>>>>

      <<<<<<<<學海無涯苦作舟!

      主站蜘蛛池模板: 国产成人无码AV片在线观看不卡| 福利成人午夜国产一区| 日本韩国日韩少妇熟女少妇| 99精品国产综合久久久久五月天| 日韩人妻无码精品无码中文字幕| 麻豆亚洲精品一区二区| 国产精品成人午夜久久| 国产精品色内内在线播放| 精品人妻伦九区久久aaa片| 国产精品自拍自在线播放| 亚洲人亚洲人成电影网站色 | 国产在线98福利播放视频| 国产精品扒开腿做爽爽爽a片唱戏| 国产精品三级中文字幕| 18禁无遮挡啪啪无码网站| 合水县| 欧美做受视频播放| 高颜值午夜福利在线观看| 国产欧美在线一区二区三| 国产av人人夜夜澡人人爽麻豆| 日韩有码国产精品一区| 亚洲免费人成视频观看| 免费观看欧美猛交视频黑人| 午夜视频免费试看| 和田市| 东京道一本热中文字幕| 亚洲一级特黄大片在线播放| 午夜亚洲AV日韩AV无码大全 | 亚洲午夜伦费影视在线观看| 久热这里只有精品12| 精品人妻少妇一区二区三区在线| 色综合久久精品亚洲国产| 好爽毛片一区二区三区四| 午夜性刺激在线观看| 99精品久久免费精品久久| 激情五月天一区二区三区| 国产精品久久久久精品日日| av中文字幕一区二区| 欧美18videosex性欧美tube1080| 国产欧美VA天堂在线观看视频| 婺源县|