POJ 1797 Heavy Transportation (Dijkstra变形)
Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64u
Description
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
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
#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
每条路都有一个限制的重量 求从1到n最多可以装载多少货物顺利通过
#include<stdio.h>
#include<string.h>
#include<iostream>
#include<algorithm>
using namespace std;
//const int inf=0x7fffffff;
const int MAXN=;
//#define typec int
const int INF=0x3f3f3f3f;//防止后面溢出,这个不能太大
bool vis[MAXN];
int dis[MAXN];
int map[MAXN][MAXN];
int n;
void Dijkstra(int beg)
{
for(int i=; i<=n; i++)
{
dis[i]=map[beg][i];
vis[i]=false;
}
dis[beg]=;
for(int j=; j<n; j++)
{
int k=-;
int Min=-;
for(int i=; i<=n; i++)
if(!vis[i]&&dis[i]>Min)
{
Min=dis[i];
k=i;
}
if(k==-)
break;
vis[k]= true;
for(int i=; i<=n; i++)
if(!vis[i]&&dis[i]<min(dis[k],map[i][k]))
{
dis[i]=min(dis[k],map[i][k]); }
}
}
int main(){
int t;
scanf("%d",&t);
int cnt=;
while(t--){
cnt++;
int m;
memset(vis,false,sizeof(vis));
scanf("%d%d",&n,&m);
/*for(int i=1;i<=n;i++){
for(int j=i;j<=n;j++){
if(i==j)
map[i][i]=0;
else
map[i][j]=map[j][i]=INF;
}
}*/
memset(map,,sizeof(map));
int u,v,w;
for(int i=;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
map[u][v]=map[v][u]=w;
}
Dijkstra();
printf("Scenario #%d:\n",cnt);
printf("%d\n",dis[n]);
puts(""); }
return ;
}
POJ 1797 Heavy Transportation (Dijkstra变形)的更多相关文章
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation SPFA变形
原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ...
- POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
随机推荐
- java文件中文在MyEclipse中打开变成了乱码
导入其他人的项目,出现乱码状况 以下是解决方案之一:
- (转)在WAMPSERVER下增加多版本的PHP(PHP5.3,PHP5.4,PHP5.5)支持
原文:http://www.cnblogs.com/lyongde/p/3745030.html 此文在原文的基础上改进了几个步骤,因为经本人实践,原文无法正确配置. WAMPServer可以让开发者 ...
- bugzilla_firefox
//本来要给火狐提交bug的,发现复现不鸟,我勒个去 <!doctype html> <html> <head> <meta charset="ut ...
- Weblogic 启动报错:java.lang.NoClassDefFoundError
Weblogic 启动报错:java.lang.NoClassDefFoundError ####<2015-6-17 下午03时30分47秒 CST> <Error> &l ...
- 【ZOJ 3480】Duck Typing
题 题意 1.有t组数据,输入时每组数据之间空格隔开,输出时也要求空格隔开. 2.每组都是一行begin开始,一行end结束. 3.class ClassName[:Super] 表示声明一个类型,S ...
- Oracle导出数据结构和数据表的方法
1.PLSQL导出数据结构(数据表.序列.触发器.函数.视图) 1)在左侧 点击tables 2)Tools-->Export User Objects 3)红色1 是你要选择导出的表,红色2 ...
- Oracle分页查询语句
SELECT * FROM (SELECT A.*, ROWNUM RN FROM (SELECT * FROM (此处添加你要分页的表)) A WHERE ROWNUM <= 14000)WH ...
- [NOIP2009] 普及组
多项式输出 模拟 /*by SilverN*/ #include<algorithm> #include<iostream> #include<cstring> # ...
- ECSHOP \admin\edit_languages.php GETSHELL Based On Injection PHP Code Into /languages/zh_cn/user.php
目录 . 漏洞描述 . 漏洞触发条件 . 漏洞影响范围 . 漏洞代码分析 . 防御方法 . 攻防思考 1. 漏洞描述 对于很多CMS网站来说,它们都需要保存很多的网站META信息,最常用的最佳实践是以 ...
- OOA/OOD/OOP(了解)
Object-Oriented Analysis:面向对象分析方法 是在一个系统的开发过程中进行了系统业务调查以后,按照面向对象的思想来分析问题.OOA与结构化分析有较大的区别.OOA所强调的是在系统 ...