首页 > 代码库 > Poj 2263 Heavy Cargo Floyd 求最大容量路
Poj 2263 Heavy Cargo Floyd 求最大容量路
f[i][j] = max(f[i][j],min(f[i][k],f[j][k]))
#include <cstdio>#include <cstring>#include <cmath>#include <algorithm>#include <climits>#include <string>#include <iostream>#include <map>#include <cstdlib>#include <list>#include <set>#include <queue>#include <stack>using namespace std;typedef long long LL;const int maxn = 205;const int INF = INT_MAX / 4;map<string,int> mp;int d[maxn][maxn],n,m;string a,b;int id(string &s) { int now = mp.size(); if(mp.count(s) == 0) mp[s] = now + 1; return mp[s];}int main() { int kase = 1; while(cin >> n >> m,n) { mp.clear(); int dist; for(int i = 1;i <= n;i++) { for(int j = 1;j <= n;j++) { d[i][j] = -1; } } for(int i = 1;i <= m;i++) { cin >> a >> b >> dist; d[id(a)][id(b)] = d[id(b)][id(a)] = dist; } for(int k = 1;k <= n;k++) { for(int i = 1;i <= n;i++) { for(int j = 1;j <= n;j++) { d[i][j] = max(d[i][j], min(d[i][k],d[j][k])); } } } cin >> a >> b; cout << "Scenario #" << kase++ << endl; cout << d[id(a)][id(b)] << " " << "tons" << endl; cout << endl; } return 0;}
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。