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 ...
随机推荐
- Task.Run Vs Task.Factory.StartNew
在.Net 4中,Task.Factory.StartNew是启动一个新Task的首选方法.它有很多重载方法,使它在具体使用当中可以非常灵活,通过设置可选参数,可以传递任意状态,取消任务继续执行,甚至 ...
- UVa 437 The Tower of Babylon
Description Perhaps you have heard of the legend of the Tower of Babylon. Nowadays many details of ...
- Linux Rootkit Sample && Rootkit Defenser Analysis
目录 . 引言 . LRK5 Rootkit . knark Rootkit . Suckit(super user control kit) . adore-ng . WNPS . Sample R ...
- iOS开发的那些坑
最近重新拿起了iOS的开发,使用OC和Swift混编,碰到了一些比较棘手的问题,在这里记录下来,方便自己以后或他人不再入坑.这篇文章的内容包含: UITableViewCell的真实结构在iOS的环境 ...
- hdu 2045 不容易系列之(3)—— LELE的RPG难题
解题思路: f(n)=1,2,.....n-2,n-1,n 前n-2个已经涂好,那么n-1有两种可能 1.n-1与n-2和1 的颜色都不同 1 粉, n-2 红, n-1 绿. 那么n的颜色 ...
- 自定义cell的步骤(每个cell的高度不一样,每个cell里面显示的内容也不一样)
1.新建一个继承自UITableViewCell的子类 2. 在initWithStyle:方法中进行子控件的初始化 1> 将有可能显示的所有子控件都添加到contentView中 2> ...
- ios 正则邮箱
- (BOOL) isEmail { NSString *emailRegEx = @"(?:[a-z0-9!#$%\\&'*+/=?\\^_`{|}~-]+(?:\\.[a-z0- ...
- pthread 学习系列 case1-- 共享进程数据 VS 进程
#include <stdio.h> #include <unistd.h> #include <stdlib.h> #include <pthread.h& ...
- WPF 窗口自定义拉伸
.NET技术交流群 199281001 .欢迎加入. //自定义窗体拉伸 public HwndSource _HwndkaifaSource; private const int WM_SYSCOM ...
- powerdesigner设置表主键列为自动增长。
powerdesigner 版本12.5 创建表就不说了.下面开始介绍设置自动增长列. 1 在表视图的列上创建.双击表视图,打开table properties ———>columens ,双击 ...