题目链接:http://poj.org/problem?id=2263
题意:题中给出相连通不同城市之间的载货量,要求找到一条从指定起点到终点的路径,并满足载货量最大。
#include <iostream> #include <cstdio> #include <cstring> #include <string> using namespace std; const int POINT = 210; int dis[POINT][POINT]; string city[POINT]; int main() { int cases = 0; int n,r; while(scanf("%d %d",&n,&r),n||r) { cases++; memset(dis,0,sizeof(dis)); int numcity = 1; for(int i=1; i<=r; i++) { string a,b; int w; cin>>a>>b>>w; int u=0,v=0; for(int j=1; j<=numcity; j++) { if(a==city[j]) u = j; if(b==city[j]) v = j; } if(u==0) { u = numcity; city[numcity++] = a; } if(v==0) { v = numcity; city[numcity++] = b; } dis[u][v] = dis[v][u] = w; } for(int k=1;k<=n;k++) { for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) dis[i][j] = max(dis[i][j],min(dis[i][k],dis[k][j])); } } string a,b; cin>>a>>b; int u,v; for(int i=1; i<=n; i++) { if(a == city[i]) u = i; if(b == city[i]) v = i; } printf("Scenario #%d\n%d tons\n\n",cases,dis[u][v]); for(int i=1;i<=n;i++) city[i].clear(); } }
时间: 2024-10-08 15:07:45