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

Heavy Transportation
Time Limit: 3000MS   Memory Limit: 30000K
Total Submissions: 24576   Accepted: 6510

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出发到n的所有路径中,限制大小最大是多少。

题解

定义dp[i]表示从1走到 i 时的限制大小的最大值。然后就像spfa那样,每次从队列里面拿点出来松弛,如果松弛成功,则入队。

代码

#include<iostream>
#include<queue>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cstdio>
#define INF 1000006
#define MAX_N 1003
using namespace std; int d[MAX_N];
int T; struct node {
public:
int u, c; node(int uu, int cc) : u(uu), c(cc) { } node() { }
}; struct edge {
public:
int to, cost; edge(int t, int c) : to(t), cost(c) { } edge() { }
}; queue<node> que;
vector<edge> G[MAX_N];
void spfa(int s) {
que.push(node(s, INF));
d[s] = INF;
while (que.size()) {
node now = que.front();
que.pop();
if (now.c != d[now.u])continue;
int u = now.u;
for (int i = ; i < G[u].size(); i++) {
int v = G[u][i].to;
int t = min(d[u], G[u][i].cost);
if (t > d[v]) {
d[v] = t;
que.push(node(v, t));
}
}
}
}
int n,m; int main() {
scanf("%d", &T);
int cas = ;
while (T--) {
scanf("%d%d", &n, &m);
for (int i = ; i <= n; i++)G[i].clear();
while (que.size())que.pop();
memset(d, , sizeof(d));
for (int i = ; i < m; i++) {
int u, v, c;
scanf("%d%d%d", &u, &v, &c);
G[u].push_back(edge(v, c));
G[v].push_back(edge(u, c));
}
spfa();
printf("Scenario #%d:\n%d\n\n", ++cas, d[n]);
}
return ;
}

POJ 1797 Heavy Transportation SPFA变形的更多相关文章

  1. POJ.1797 Heavy Transportation (Dijkstra变形)

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

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

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

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

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

  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 (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: 31882   Accept ...

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

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

  8. poj 1797 Heavy Transportation(最短路径Dijkdtra)

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

  9. POJ 1797 Heavy Transportation (最大生成树)

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

随机推荐

  1. Struts2和Spring MVC 区别 今天面试被问到了

    虽然说没有系统的学习过Spring MVC框架, 但是工作这么长时间, 基本上在WEB层使用的都是Spring MVC, 自己觉得Struts2也是一个不错的WEB层框架, 这两种框架至今自己还未有比 ...

  2. The 2018 ACM-ICPC Chinese Collegiate Programming Contest Take Your Seat

    /* 证明过程如下 :第一种情况:按1到n的顺序上飞机,1会随意选一个,剩下的上去时若与自己序号相同的座位空就坐下去,若被占了就也会随意选一个.求最后一个人坐在应坐位置的概率 */ #include ...

  3. redis--py操作redis【转】

    Python操作redis 请给作者点赞--> 原文链接 python连接方式:点击 下面介绍详细使用 1.String 操作 redis中的String在在内存中按照一个name对应一个val ...

  4. Markdown 使用锚点

    首先是建立一个跳转的连接: [说明文字](#jump) 然后标记要跳转到什么位置即可: <span id = "jump">跳转到这里:</span>

  5. BZOJ 5334: [Tjoi2018]数学计算

    线段树裸题 难度在于认识到这个没法线性做 #include<cstdio> using namespace std; int n,mod,tr[400005]; void insert(i ...

  6. HDU 2852 KiKi's K-Number 主席树

    题意: 要求维护一个数据结构,支持下面三种操作: \(0 \, e\):插入一个值为\(e\)的元素 \(1 \, e\):删除一个值为\(e\)的元素 \(2 \, a \, k\):查询比\(a\ ...

  7. Pycharm Django开发(一)设置开发环境

    一 由于我是一个对开发环境有强迫症的人,在装完PYTHON 2.6 3.3  3.4中,在创建Django工程的时候,会出现N个版本的python,那么在这里可以设置你喜欢和要使用的版本.

  8. seleniumIDE使用

    1.selenium IDE使用:适用于火狐浏览器 2.界面按钮包括录制(右上角的红点),运行脚本(中上页的绿色三角,包括依次运行和单个运行的2个运行按钮) 3.导出文件为.java,在文件选项中

  9. 对python的想法

    作为计算机专业的学生,在编程语言之余,我认为掌握一门脚本语言是很必要的.尤其是现在在数据分析,AI,机器学习等各个方面都大放异彩的python.相比于之前接触过的Java,C,C++乃至于php等语言 ...

  10. [python][oldboy]list append, extend

    # coding=utf8 li = [1, 3, [1, "liu"], "liu"] print li li.append([1, 2]) print li ...