POJ 2263 最短路 路径上最小值
2013-08-18 23:38
337 查看
修改floyd
mp[i][j] = MAX(mp[i][j], MIN(mp[i][k], mp[k][j]));
mp[i][j] = MAX(mp[i][j], MIN(mp[i][k], mp[k][j]));
#include <set> #include <map> #include <cmath> #include <queue> #include <stack> #include <string> #include <cstdio> #include <cstring> #include <iostream> #include <algorithm> using namespace std; typedef long long LL; const double PI = acos(-1.0); template <class T> inline T MAX(T a, T b){if (a > b) return a;return b;} template <class T> inline T MIN(T a, T b){if (a < b) return a;return b;} const int N = 111; const int M = 11111; const LL MOD = 1000000007LL; const int dir[4][2] = {1, 0, -1, 0, 0, -1, 0, 1}; const int INF = 0x3f3f3f3f; int mp[222][222]; int main() { int n, m; int cas = 1; while (cin >> n >> m, n && m) { string name1, name2; int i, j, k, u, v, w, cnt = 1; map < string, int> index; memset(mp, 0, sizeof(mp)); for (i = 0; i < m; ++i) { cin >> name1 >> name2 >> w; if (!index[name1]) u = index[name1] = cnt++; else u = index[name1]; if (!index[name2]) v = index[name2] = cnt++; else v = index[name2]; mp[u][v] = mp[v][u] = w; } for (k = 1; k <= n; ++k) for (i = 1; i <= n; ++i) for (j = 1; j <= n; ++j) { mp[i][j] = MAX(mp[i][j], MIN(mp[i][k], mp[k][j])); } cin >> name1 >> name2; u = index[name1]; v = index[name2]; // printf("%d %d\n",u, v); printf("Scenario #%d\n%d tons\n\n", cas++, mp[u][v]); } return 0; }
相关文章推荐
- poj 3216 最短路+最小路径
- poj 3216 Repairing Company(最短路Floyd + 最小路径覆盖 + 构图)
- poj2522 Frogger(最短路变形 所有路径中最长边的最小值)
- POJ 2253 Frogger (单源最短路变型 求路径上最大边权值的最小值)
- POJ-2253 Frogger(利用dijkstra最短路求最大路径最小边)
- POJ 2253 Frogger【最短路变形——路径上最小的最大权】
- POJ 2253 Frogger【最短路变形——路径上最小的最大权】
- poj 3216 最短路+最小路径
- poj 2060 Taxi Cab Scheme 最小路径覆盖
- POJ 3020——Antenna Placement——————【 最小路径覆盖、奇偶性建图】
- POJ-2594-Treasure Exploration-(路径相交的最小路径覆盖+闭包传递)
- poj 2594 Treasure Exploration(最小路径覆盖+闭包传递)
- poj2449 第k短路 (单源最短路径+A*)
- HDU 4606 Occupy Cities (计算几何+最短路+二分+最小路径覆盖)
- poj2594 Treasure Exploration(可相交最小路径覆盖)
- POJ 2594 Treasure Exploration(传递闭包+最小路径覆盖)
- POJ 2594 Treasure Exploration(最小路径覆盖变形)
- poj 3216 Flyod+最小路径覆盖
- POJ 1797 Heavy Transportation(最小生成树或最短路)
- (POJ 2253)Frogger 求所有可达路径中的最大边的最小值 dijkstra || floyd 变形