poj 1797 Heavy Transportation(最短路径Dijkdtra)

时间:2022-09-04 13:15:56
Heavy Transportation
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 26968   Accepted: 7232

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.

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
题目大意,有n个城m条边,每个边有个最大的通过量,求1城市到n城市的一条最大通路容量是多少
迪杰斯特拉算法的变形,松弛条件改为道路容量为道路上容量最小的边,然后在选容量最大的路
ac代码如下:
 #include<iostream>
#include<algorithm>
#include<cstring>
#include<memory.h>
using namespace std;
long map[][];
long dp[],n;
bool v[];
void dij(int ii){
for(int i=;i<=n;i++){
dp[i]=map[ii][i];
}
dp[ii]=;v[ii]=;
int T=n;
while(T--){
int k=-,s;
for(int i=;i<=n;i++){//找下一条边
if(dp[i]>k&&!v[i]){
k=dp[i];
s=i;
}
}
v[s]=;
if(s==n)return;
for(int i=;i<=n;i++){//利用下一条边进行松弛
if(!v[i]&&dp[i]<min(dp[s],map[s][i])){
dp[i]=min(dp[s],map[s][i]);
}
}
}
}
int main(){
long T,m,s,e,c,ca=;
cin>>T;
while(T--){
cin>>n>>m;
memset(v,,sizeof(v));
memset(dp,,sizeof(dp));
memset(map,,sizeof(map));
for(int i=;i<=m;i++){
cin>>s>>e>>c;
map[s][e]=map[e][s]=max(map[s][e],c);
}
dij();
cout<<"Scenario #"<<ca++<<":"<<endl;
cout<<dp[n]<<endl<<endl;
}
return ;
}

提交结果:

poj 1797 Heavy Transportation(最短路径Dijkdtra)

poj 1797 Heavy Transportation(最短路径Dijkdtra)的更多相关文章

  1. POJ 1797 Heavy Transportation &sol; SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  2. poj 1797 Heavy Transportation(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  3. POJ&period;1797 Heavy Transportation &lpar;Dijkstra变形&rpar;

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  4. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  5. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  6. POJ 1797 &Tab;Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  7. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  8. POJ 1797 Heavy Transportation &lpar;最大生成树&rpar;

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  9. POJ 1797 Heavy Transportation &lpar;Dijkstra&rpar;

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

随机推荐

  1. Linux 服务器监控

    200 ? "200px" : this.width)!important;} --> 标签:iostat/free/top/dstat 概述 文字主要讲述使用linux自带 ...

  2. springMVC乱码问题-转

    彻底解决Spring MVC 中文乱码 问题     1:表单提交controller获得中文参数后乱码解决方案 注意:  jsp页面编码设置为UTF-8 form表单提交方式为必须为post,get ...

  3. C&num;设计模式——桥接模式&lpar;Bridge Pattern&rpar;

    一.概述在软件开发中,我们有时候会遇上一个对象具有多个变化维度.比如对汽车对象来说,可能存在不同的汽车类型,如公共汽车.轿车等,也可能存在不同的发动机,如汽油发动机.柴油发动机等.对这类对象,可应用桥 ...

  4. Linux Qt动态库的创建和使用

    一.创建动态库 编写一个共享库类,比如: //..base.h class Base : public QObject { Q_OBJECT public: ); void PrintLog(QStr ...

  5. windows下多个python版本共存

    方法/步骤   首先当然是安装你需要的两个不同版本的python,这里我安装的是2.7和3.3的,两个版本安装顺序无所谓.   接下来就是检查环境变量,缺少的我们需要添加.先找到环境变量的位置.   ...

  6. Leetcode OJ &colon; Merge k Sorted Lists 归并排序&plus;最小堆 mergesort heap C&plus;&plus; solution

    /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode ...

  7. cssText设置css样式

    js中用cssText设置css样式 (2012-08-21 10:40:22) 转载▼ 标签: js   如果网页中一个 id为“no”的标签,暂且当div标签来tell:想要在js中设置这个div ...

  8. Hibernate 关联查询 相关错误

    错误提示: could not resolve property: 确定有相关属性时,记得使用 criteria.createAlias @ManyToOne 若可能为null 要加上 @NotFou ...

  9. PHP全选择删除功能

    <script type="text/javascript" language="javascript"> function selectBox(s ...

  10. 项目架构开发:数据访问层之UnitOfWork

    接上文 项目架构开发:数据访问层之IQuery 本章我们继续IUnitOfWork的开发,从之前的IRepository接口中就可以看出,我们并没有处理单元事务, 数据CUD每次都是立即执行的,这样有 ...