欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

Agri-Net (poj 1258 最短路+prim)

程序员文章站 2022-08-03 15:54:35
language: default agri-net time limit: 1000ms memory limit: 10000k total subm...
language: agri-net
time limit: 1000ms memory limit: 10000k
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 exceed 100,000.

input

the input includes several cases. for each case, the first line contains the number of farms, n (3 =>=>

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

source

usaco 102

模板题,直接套模板。。。

代码:

#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-6
typedef 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;imp[now][j])
                dist[j]=mp[now][j];
    }
    int ans=0;
    for (i=0;i