题目链接:http://poj.org/problem?id=1797

Heavy Transportation
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 39999   Accepted: 10515

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

Source

TUD Programming Contest 2004, Darmstadt, Germany
 
 
 
题解:
1.最短路径的变形:把dis[]从原来的记录最短距离 变为 记录不同路径上最小边权中的最大值。
2.利用dijkstra算法时,每次松弛都是选取dis的最大值。
 
 
代码如下:
 #include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define rep(i,a,n) for(int (i) = a; (i)<=(n); (i)++)
#define ms(a,b) memset((a),(b),sizeof((a)))
using namespace std;
typedef long long LL;
const double EPS = 1e-;
const int INF = 2e9;
const LL LNF = 9e18;
const int MOD = 1e9+;
const int MAXN = 1e3+; int n, m; struct edge
{
int to, w, next;
}edge[MAXN*MAXN];
int cnt, head[MAXN]; void addedge(int u, int v, int w)
{
edge[cnt].to = v;
edge[cnt].w = w;
edge[cnt].next = head[u];
head[u] = cnt++;
} void init()
{
cnt = ;
memset(head, -, sizeof(head));
} int dis[MAXN];
bool vis[MAXN];
void dijkstra(int st)
{
memset(vis, , sizeof(vis));
for(int i = ; i<=n; i++)
dis[i] = (i==st?INF:); for(int i = ; i<=n; i++)
{
int k, maxx = ;
for(int j = ; j<=n; j++)
if(!vis[j] && dis[j]>maxx)
maxx = dis[k=j]; vis[k] = ;
for(int j = head[k]; j!=-; j = edge[j].next)
if(!vis[edge[j].to])
dis[edge[j].to] = max(dis[edge[j].to], min(dis[k], edge[j].w) );
}
} int x[MAXN], y[MAXN];
int main()
{
int T;
scanf("%d", &T);
for(int kase = ; kase<=T; kase++)
{
scanf("%d%d", &n, &m);
init();
for(int i = ; i<=m; i++)
{
int u, v, w;
scanf("%d%d%d", &u, &v, &w);
addedge(u,v,w);
addedge(v,u,w);
} dijkstra();
printf("Scenario #%d:\n",kase);
printf("%d\n\n", dis[n]);
}
}
 

POJ1797 Heavy Transportation —— 最短路变形的更多相关文章

  1. POJ--1797 Heavy Transportation (最短路)

    题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...

  2. POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)

    题目:click here 题意: 有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量.分析: 其实这个求最大边可以 ...

  3. POJ-1797Heavy Transportation,最短路变形,用dijkstra稍加修改就可以了;

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K          Description Background  Hugo ...

  4. (Dijkstra) POJ1797 Heavy Transportation

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 53170   Accepted:  ...

  5. POJ 1797 Heavy Transportation (Dijkstra变形)

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

  6. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  7. POJ1797 Heavy Transportation 【Dijkstra】

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 21037   Accepted:  ...

  8. poj1797 - Heavy Transportation(最大边,最短路变形spfa)

    题目大意: 给你以T, 代表T组测试数据,一个n代表有n个点, 一个m代表有m条边, 每条边有三个参数,a,b,c表示从a到b的这条路上最大的承受重量是c, 让你找出一条线路,要求出在这条线路上的最小 ...

  9. [POJ1797] Heavy Transportation(最大生成树 || 最短路变形)

    传送门 1.最大生成树 可以求出最大生成树,其中权值最小的边即为答案. 2.最短路 只需改变spfa里面的松弛操作就可以求出答案. ——代码 #include <queue> #inclu ...

随机推荐

  1. 动态添加radiogroup

    private LinearLayout layout; //布局 , 可以在xml布局中获得 private RadioGroup group ; //点选按钮组 public void onCre ...

  2. (4)Swing布局

    一.FlowLayout-流布局 新增第一个组件后默认在第一行的居中位置,之后 组件按照加入的先后顺序按照设置的对齐方式从左向右排列 二.borderLayout-边框布局 容器划分为东.西.南.北. ...

  3. 使用Swagger生成Spring Boot REST客户端(支持Feign)(待实践)

    如果项目上使用了Swagger做RESTful的文档,那么也可以通过Swagger提供的代码生成器生成客户端代码,同时支持Feign客户端. 但是经过测试,生成Feign代码和REST客户端有些臃肿. ...

  4. 【IntelliJ IDEA】2017.3.4版本永久破解

    [本版本软件包和破解jar在网盘上有    我的网盘--技术--idea破解所需要的] 1.idea官网下载 历史版本 选择2017.3.4版本下载 https://www.jetbrains.com ...

  5. 【转载】容器技术 & Docker & 与虚拟化的比较

    看到10月份天天写博客,只有一天没写,非常棒! 11月份也基本每天都写,现在看到有三天没加新博客,应该是之前挖的坑太多了,需要填坑,呵呵. 那这篇文章是不是为了占坑呢?哈哈.我不说话. 容器技术,这篇 ...

  6. MongoDB副本集的原理,搭建

    介绍: mongodb副本集即客户端连接到整个副本集,不关心具体哪一台机器是否挂掉.主服务器负责整个副本集的读写,副本集定期同步数据备份,一旦主节点挂掉,副本节点就会选举一个新的主服务器,这一切对于应 ...

  7. 配置 yum 源相关

    1. 修改yum配置 http://www.cnblogs.com/shuaixf/archive/2011/11/30/2268496.html 2. centos安装 epel 源 https:/ ...

  8. [Node.js] Trigger a File Download in Express

    Downloading and saving a file is a common scenario when building out your web application. Using Exp ...

  9. 零售连锁行业SOA化解决方式

    零售连锁行业面临的问题 1.店铺老化.营销手段单一落后. 2.管理模式的不科学,我国零售企业在起家时候并没有一套完好的科学的管理及考评系统的存在.而且在企业的发展过程中并未学习建立.对于人才的吸引.培 ...

  10. android 4.4以上能够实现的沉浸式状态栏效果

    仅仅有android4.4以及以上的版本号才支持状态栏沉浸效果 先把程序执行在4.4下面的手机上,看下效果: 在4.4以上的效果: watermark/2/text/aHR0cDovL2Jsb2cuY ...