POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797
Heavy Transportation
Time Limit: 3000MS | Memory Limit: 30000K | |
Total Submissions: 30840 | Accepted: 8191 |
Description
Background
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed on which all streets can carry the weight.
Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know.
Problem
You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's place). You may assume that there is at least one path. All streets can be travelled in both directions.
Input
The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.
Output
The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer. Terminate the output for the scenario with a blank line.
Sample Input
1 3 3 1 2 3 1 3 4 2 3 5
Sample Output
Scenario #1: 4
题目大意:样例个数T,给定N个点,及M条边的最大负载,求顶点1到N的最大流。
// 1.给定一个双向可达的有向图,求出1->n之间的所有可达路径,每条路径中的最小边的最大值。
AC代码:

1 #include <stdio.h> 2 #include <string.h> 3 #include <algorithm> 4 using namespace std; 5 int visit[1010]; 6 int dis[1010]; 7 int p[1010][1010]; 8 int n; 9 int dijkstra() 10 { 11 int i,j,pos,minn; 12 for (i = 1; i <= n; i ++) 13 { 14 dis[i] = p[1][i]; 15 visit[i] = 0; 16 } 17 dis[1] = 0; 18 visit[1] = 1; 19 20 for (i = 1; i <= n; i ++) 21 { 22 minn = 0; 23 for (j = 1; j <= n; j ++) 24 { 25 if (!visit[j] && dis[j] > minn) 26 { 27 minn = dis[j]; 28 pos = j; 29 } 30 } 31 visit[pos] = 1; 32 for (j = 1; j <= n; j ++) 33 { 34 if(!visit[j] && dis[j] < min(dis[pos],p[pos][j])) 35 dis[j] = min(dis[pos],p[pos][j]); 36 } 37 } 38 return dis[n]; 39 } 40 int main() 41 { 42 int t,m,x,y,z,i,j,f = 1; 43 scanf("%d",&t); 44 while (t --) 45 { 46 scanf("%d%d",&n,&m); 47 for (i = 1; i <= n; i ++) 48 for (j = 1; j <= n; j ++) 49 p[i][j] = 0; 50 for (i = 0; i < m; i ++) 51 { 52 scanf("%d%d%d",&x,&y,&z); 53 p[x][y] = p[y][x] = z; 54 } 55 printf("Scenario #%d:\n",f ++); 56 printf("%d\n\n",dijkstra()); //注意格式 57 } 58 }
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】博客园社区专享云产品让利特惠,阿里云新客6.5折上折
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步