POJ 3615 Cow Hurdles

Posted Lorazepam

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 3615 Cow Hurdles相关的知识,希望对你有一定的参考价值。

http://poj.org/problem?id=3615

floyd 最短路径的变形 dist[i][j]变化为 : i j之间的最大边

 

那么输入的时候可以直接把dist[i][j] 当作i j 之间的边进行输入

转移方程 dist[i][j] = max(dist[i][j], min(dist[i][k], dist[k][j]))

 1 #include <iostream>
 2 #include <string.h>
 3 #include <stdio.h>
 4 #define INF 0x3fffffff
 5 using namespace std;
 6 const int maxn = 305;
 7 int Map[maxn][maxn];
 8 
 9 int dist[maxn][maxn];//dist[i][j]表示 i 到 j 的最大边是多少?
10 //转移方程 dist[i][j] = min( dist[i][j] ,max(dist[i][k], dist[k][j])) ---> "**"
11 //
12 //与floyd的区别 dist是 i-j的最短‘距离‘
13 int main()
14 {
15     int m, n, k;
16     scanf("%d%d%d", &m, &n, &k);
17     for(int i = 1; i <= m; i++)
18         for (int j = 1; j <= m; j++)
19             dist[i][j] = INF;
20     for (int i = 0; i < n; i++)
21     {
22         int from, to, cost;
23         scanf("%d%d%d", &from, &to, &cost);
24         dist[from][to] = cost;
25     }
26     for(int i = 1; i <= m; i++)
27     {
28         for (int j = 1; j <= m; j++)
29         {
30             for (int k = 1; k <= m; k++)
31             {
32                // if (dist[j][k] == -1) dist[j][k] = max(dist[j][i], dist[i][k]);
33                 //else
34                     dist[j][k] = min(dist[j][k], max(dist[j][i], dist[i][k]));
35             }
36         }
37     }
38     for (int i = 0; i < k; i++)
39     {
40         int from, to;
41         scanf("%d%d", &from, &to);
42         if (dist[from][to] == INF) cout << -1 << endl;
43         else  cout << dist[from][to] << endl;
44     }
45     return 0;
46 }

 

以上是关于POJ 3615 Cow Hurdles的主要内容,如果未能解决你的问题,请参考以下文章

POJ3615Cow Hurdles 最短路,你若LCA,我仍不拦你。

POJ3615 Cow HurdlesFloyd算法

P2888 [USACO07NOV]牛栏Cow Hurdles

洛谷 P2888 [USACO07NOV]牛栏Cow Hurdles

BZOJ 1641 USACO 2007 Nov. Cow Hurdles 奶牛跨栏

BZOJ 1641 [Usaco2007 Nov]Cow Hurdles 奶牛跨栏:新版floyd路径上最大边最小