关闭

POJ-2395 Out of Hay

121人阅读 评论(0) 收藏 举报
#include<iostream>
const int maxn=2016,maxm=20010,oo=1000000000;
using namespace std;
struct node{int t,ne,w;}a[maxm];//结构体的链式前向星 
int ks[maxn],e,d[maxn],p[maxn],ans;
void add(int x,int y,int z){、
	a[++e].t=y;
 	a[e].ne=ks[x];	
	ks[x]=e;
	a[e].w=z;
}//链式前向星 
int main(){
	int i,j,k,n,m;
	cin>>n>>m;
	for(i=1;i<=m;i++){int x,y,z; cin>>x>>y>>z;	add(x,y,z);add(y,x,z); 	}
	for(i=1;i<=n;i++)d[i]=oo;
	d[1]=0;
	for(i=1;i<=n;i++){
		int zx=oo;
		for(j=1;j<=n;j++)
			if(!p[j] && d[j]<zx){
				zx=d[j];k=j;
			}
		p[k]=1;ans=ans<zx?zx:ans;
		for(j=ks[k];j;j=a[j].ne)
			if(!p[a[j].t] && d[a[j].t]>a[j].w)//找到更优的路径 
				d[a[j].t]=a[j].w;
	}
	cout<<ans<<endl;
	return 0;
} 

1
0
查看评论

poj-2395 Out of Hay

The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay situatio...
  • we1215053460
  • we1215053460
  • 2017-07-20 14:03
  • 77

POJ-2395 Out of Hay

The cows have run out of hay, a horrible event that must be remedied immediately. Bessie intends to visit the other farms to survey their hay situatio...
  • fff217
  • fff217
  • 2017-07-20 17:40
  • 106

POJ 2395 Out of Hay 最小生成树

来源 USACO 2005 March Silver 题目大意 有N(2-2000)个农场,M(1-10000)条通路连通各个农场,长度不超109,要求遍历全部的农场,且每走1单位长度就要消耗一单位水,每到一个农场可以把自己的水充满,求最小的水箱容量。 样例输入 3 3 1 2 ...
  • Sci_M3
  • Sci_M3
  • 2016-03-19 17:02
  • 715

Out of Hay

Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13094 Accepted: 5078Description The cows have run out of hay, a h...
  • huayunhualuo
  • huayunhualuo
  • 2015-08-14 19:00
  • 497

POJ 2395 Out of Hay(最小生成树—prim算法记录最大边)

Out of Hay Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13609 Accepted:...
  • zwj1452267376
  • zwj1452267376
  • 2016-01-14 17:34
  • 706

BZOJ_P1682 [Usaco2005 Mar]Out of Hay 干草危机(最小生成树)

BZOJ传送门Time Limit: 5 Sec Memory Limit: 64 MB Submit: 487 Solved: 329 [Submit][Status][Discuss] DescriptionThe cows have run out of hay, a horribl...
  • qq_18455665
  • qq_18455665
  • 2016-03-25 08:17
  • 396

POJ_2395_Out of Hay【基础最小生成树】

Time Limit:1000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description Th...
  • huangshuai147
  • huangshuai147
  • 2017-03-14 11:53
  • 123

Out of Hay(poj2395)(并查集)

Out of Hay Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11580   Accepted: 4515 Description Th...
  • hdd871532887
  • hdd871532887
  • 2014-11-16 01:59
  • 1119

POJ2395 Out of Hay【Kruskal】

题目大意:1号农场的草被牛吃完了,Bessie必须从其他农场运草回来,总共有N个农场,Bessie要 去其他所有的农场运草回来,他想要使总路程最短并且路线能连接所有的农场。必须要考虑到路上 带的水袋大小。因为水袋大小和路线中距离最长的两个农场之间的路有关,现在Bessie想要求出满 足要求的路线中两...
  • u011676797
  • u011676797
  • 2015-01-24 20:25
  • 1163

TOJ 1638 Out of Hay / prim

Out of Hay 时间限制(普通/Java):1000MS/10000MS     运行内存限制:65536KByte   描述 The cows have run out of hay, a horrible event that mus...
  • u011686226
  • u011686226
  • 2013-10-22 15:18
  • 1067
    个人资料
    • 访问:9551次
    • 积分:635
    • 等级:
    • 排名:千里之外
    • 原创:49篇
    • 转载:0篇
    • 译文:0篇
    • 评论:5条