标签:
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 3768 | Accepted: 2013 |
Description
Input
Output
Sample Input
4 3 Karlsruhe Stuttgart 100 Stuttgart Ulm 80 Ulm Muenchen 120 Karlsruhe Muenchen 5 5 Karlsruhe Stuttgart 100 Stuttgart Ulm 80 Ulm Muenchen 120 Karlsruhe Hamburg 220 Hamburg Muenchen 170 Muenchen Karlsruhe 0 0
Sample Output
Scenario #1 80 tons Scenario #2 170 tons
Source
#include <cstdio> #include <iostream> #include <cstdlib> #include <algorithm> #include <ctime> #include <cmath> #include <string> #include <cstring> #include <stack> #include <queue> #include <list> #include <vector> #include <map> #include <set> using namespace std; const int INF=0x3f3f3f3f; const double eps=1e-10; const double PI=acos(-1.0); #define maxn 500 map<string, int> a; char s1[32]; char s2[32]; int c[maxn][maxn]; int v[maxn][maxn]; int pre[maxn][maxn]; int main() { int n, m, w; int cas = 0; while(~scanf("%d%d",&n,&m)&&(n+m)) { int cnt = 0; memset(c, 0, sizeof c); for(int i = 0; i < m; i++) { scanf("%s%s%d", s1, s2, &w); if(!a.count(s1)) a[s1] = cnt++; if(!a.count(s2)) a[s2] = cnt++; c[a[s1]][a[s2]] = c[a[s2]][a[s1]] = w; } // map<string, int>::iterator it; // for(it=a.begin();it!=a.end();++it) // cout<<"key: "<<it->first <<" value: "<<it->second<<endl; for(int i = 0; i < n; i++) for(int j = 0; j < n; j++) { v[i][j] = c[i][j]; pre[i][j] = i; } for(int k = 0; k < n; k++) for(int i = 0; i<n; i++) for(int j = 0; j < n; j++) { v[i][j] = max(v[i][j], min(v[i][k],v[k][j])); pre[i][j] = pre[k][j]; } scanf("%s%s",s1,s2); printf("Scenario #%d\n", ++cas); printf("%d tons\n",v[a[s1]][a[s2]]); puts(""); } return 0; }
POJ 2263 Heavy Cargo(Floyd + map)
标签:
原文地址:http://www.cnblogs.com/ZP-Better/p/4714803.html