【POJ3615】Cow Hurdles 最短路,你若LCA,我仍不拦你。

NOIP2013货车运输。仅仅只是数据范围小了很多。

不到150s打完而且AC。

额。当然。我写的是Floyd。

写LCA的真过分。

#include <cstdio>
#include <cstring>
#include <algorithm>
#define N 305
#define inf 0x3f3f3f3f
using namespace std;
int n,m,q;
int map[N][N];
int main()
{
//	freopen("test.in","r",stdin);
	int i,j,k;
	int a,b,c;
	scanf("%d%d%d",&n,&m,&q);
	memset(map,0x3f,sizeof(map));
	for(i=1;i<=m;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		map[a][b]=min(map[a][b],c);
	}
	for(k=1;k<=n;k++)for(i=1;i<=n;i++)for(j=1;j<=n;j++)map[i][j]=min(map[i][j],max(map[i][k],map[k][j]));
	for(i=1;i<=q;i++)
	{
		scanf("%d%d",&a,&b);
		printf("%d\n",map[a][b]<inf?

map[a][b]:-1);
	}
	return 0;
}
时间: 2024-10-16 17:52:58

【POJ3615】Cow Hurdles 最短路,你若LCA,我仍不拦你。的相关文章

POJ3615 Cow Hurdles【Floyd】

Cow Hurdles Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 6155 Accepted: 2760 Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are gett

POJ 3615 Cow Hurdles (Floyd算法)

Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6142   Accepted: 2752 Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are

1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏

1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏 Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 424  Solved: 272[Submit][Status] Description Farmer John 想让她的奶牛准备郡级跳跃比赛,贝茜和她的伙伴们正在练习跨栏.她们很累,所以她们想消耗最少的能量来跨栏. 显然,对于一头奶牛跳过几个矮栏是很容易的,但是高栏却很难.于是,奶牛们总是关心路径上最高的栏的高度. 奶牛的训练场

BZOJ 1641: [Usaco2007 Nov]Cow Hurdles 奶牛跨栏( floyd )

直接floyd.. ---------------------------------------------------------------------------- #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #define rep( i , n ) for( int i = 0 ;  i < n ; ++i ) #define clr( x

【POJ 3615】Cow Hurdles

Cow Hurdles Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6486   Accepted: 2948 Description Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are

洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles

洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles 题目描述 Farmer John wants the cows to prepare for the county jumping competition, so Bessie and the gang are practicing jumping over hurdles. They are getting tired, though, so they want to be able to use as little ene

【poj3615】 Cow Hurdles

http://poj.org/problem?id=3615 (题目链接) 题意 给出一张有向图,求从u到v最大边最小的路径的最大边.→_→不会说话了.. Solution 好久没写Floyd了,水一发.邻接表都不用打... 代码 // poj3615 #include<algorithm> #include<iostream> #include<cstdlib> #include<cstring> #include<cstdio> #inclu

POJ-3268 Silver Cow Party( 最短路 )

题目链接:http://poj.org/problem?id=3268 Description One cow from each of N farms (1 ≤ N ≤ 1000) conveniently numbered 1..N is going to attend the big cow party to be held at farm #X (1 ≤ X ≤ N). A total of M (1 ≤ M ≤ 100,000) unidirectional (one-way road

BZOJ 1631: [Usaco2007 Feb]Cow Party( 最短路 )

这道题和蔡大神出的今年STOI初中组的第二题几乎一模一样... 先跑一遍最短路 , 再把所有边反向 , 再跑一遍 , 所有点两次相加的最大值即为answer ----------------------------------------------------------------------------- #include<cstdio> #include<algorithm> #include<cstring> #include<queue> #in