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 ...
随机推荐
- 学习之路三十五:Android和WCF通信 - 大数据压缩后传输
最近一直在优化项目的性能,就在前几天找到了一些资料,终于有方案了,那就是压缩数据. 一丶前端和后端的压缩和解压缩流程 二丶优点和缺点 优点:①字符串的压缩率能够达到70%-80%左右 ②字符串数量更少 ...
- AngularJS开发指南1:AngularJS简介
什么是 AngularJS? AngularJS 是一个为动态WEB应用设计的结构框架.它能让你使用HTML作为模板语言,通过扩展HTML的语法,让你能更清楚.简洁地构建你的应用组件.它的创新点在于, ...
- 每天一个linux命令(50):telnet命令
telnet 命令通常用来远程登录.telnet程序是基于TELNET协议的远程登录客户端程序.Telnet协议是TCP/IP协议族中的一员,是 Internet远程登陆服务的标准协议和主要方式.它为 ...
- 团队作业--Beta版本冲刺
项目冲刺随笔 第一天 第二天 第三天 第四天 第五天 第六天 第七天
- java核心数据结构总结
JDK提供了一组主要的数据结构的实现,如List.Set.Map等常用结构,这些结构都继承自java.util.collection接口. List接口 List有三种不同的实现,ArrayList和 ...
- 设置java jvm(虚拟机) 的内存在大小
package WanWan; public class Test { /** * @param args */ public static void main(String[] args) { // ...
- iOS边练边学--父子控制器之自定义控制器的切换
一.如图所示的界面,按钮One.Two.Three分别对应三个控制器的view,点击实现切换.个人感觉父子控制器的重点在于,控制器的view们之间建立了父子关系,控制器不建立的话,发生在view上面的 ...
- Json-转换
js转换 引用json.js(将json格式转换成字符串 var name = document.getElementById("name").value; var retries ...
- Hibernate-一级缓存session
hibernate提供的一级缓存 hibernate是一个线程对应一个session,一个线程可以看成一个用户.也就是说session级缓存(一级缓存)只能给一个线程用,别的线程用不了,一级缓存就是和 ...
- The big deffrence between ($(du * )) and $(du *)
Infolist=($(du *))echo "Get the list one $Infolist"This has formed a array after quating t ...