POJ
来源:互联网 发布:php论文范文参考5000字 编辑:程序博客网 时间:2024/06/08 14:36
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.
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
找到最大负载,转换成最短路径问题。
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#define inf 0x3f3f3f3fusing namespace std;int d[1001];//最短路径在这里是最大负载int w[1001][1001];bool vis[1001];int n,m;void dijkstra(){ memset(vis,0,sizeof(vis)); for(int i=1;i<=n;i++) { d[i]=w[1][i]; } for(int k=1;k<=n;k++) { int a=0,min1=-1; for(int i=1;i<=n;i++) { if(!vis[i]&&d[i]>min1) { a=i; min1=d[i]; } } vis[a]=1; for(int j=1;j<=n;j++) { if(!vis[j]&&min(d[a],w[a][j])>d[j])//只用把这里改为更新最大负载即可 { d[j]=min(d[a],w[a][j]); } } }}int main(){ int t; scanf("%d",&t); for(int k=1;k<=t;k++) { scanf("%d%d",&n,&m); for(int i=1;i<=n;i++) { for(int j=1;j<=n;j++) { w[i][j]=0; } } int a,b,c; for(int i=0;i<m;i++) { scanf("%d%d%d",&a,&b,&c); w[a][b]=c; w[b][a]=c; } dijkstra(); printf("Scenario #%d:\n",k); printf("%d\n\n",d[n]); } return 0;}
- POJ
- poj
- POJ
- POJ
- poj
- poj
- POJ
- POJ
- poj
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- POJ
- ExpandableListView 根据输入的名称搜索对应的内容并展示,点击可打开二级列表
- Java:Date、Calendar、Timestamp的区别、相互转换与使用
- cv::sort和cv::sortIdx
- HDU-2476(区间DP)
- MySQL 添加用户
- POJ
- 水经微图下载与安装教程
- 远程桌面xfce4 中 tab 补全键 冲突
- 《C++ Primer》读书笔记第三章-4-数组 And 多维数组
- C#开发XML WebService接口(SOAP)
- [笔记分享] [DT] device tree之属性
- InnoDB存储引擎--3、分布式事务XA
- [JAVA] Spring AOP API简述
- JAVA反射与注解