jasperexception,好瘦嘉嘉董事招代理,天宝纪事
language:
agri-net
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 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
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
Net Core Web Api项目与在NginX下发布的方法
asp.net core3.1 引用的元包dll版本兼容性问题解决方案
IdentityServer4实现.Net Core API接口权限认证(快速入门)
ASP.NET Core MVC通过IViewLocationExpander扩展视图搜索路径的实现
网友评论