Agri-Net (poj 1258 Shortest Path + prim)

Source: Internet
Author: User

Agri-Net (poj 1258 Shortest Path + prim)

Language:DefaultAgri-Net
Time Limit:1000 MS Memory Limit:10000 K
Total Submissions:40905 Accepted:16682

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 be exceed 100,000.

Input

The input parameter des 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

40 4 9 214 0 8 179 8 0 1621 17 16 0

Sample Output

28

Source

USACO 102

Template question, directly set the template...

Code:

#include 
 
  #include 
  
   #include 
   
    #include #include 
    
     #include 
     
      #include 
      #include 
       
        #include 
        
         #include 
         
          #include 
          
           #pragma comment (linker,"/STACK:102400000,102400000")#define maxn 105#define MAXN 2005#define mod 1000000009#define INF 0x3f3f3f3f#define pi acos(-1.0)#define eps 1e-6typedef long long ll;using namespace std;int N;int mp[maxn][maxn],visit[maxn],dist[maxn];void prim(){ int i,j,mi,now; memset(visit,0,sizeof(visit)); memset(dist,INF,sizeof(dist)); for (i=0;i
           
            mp[now][j]) dist[j]=mp[now][j]; } int ans=0; for (i=0;i
            
             



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.