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

┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉┉┉ ∞ ∞ ┉┉┉┉ ∞ ∞ ┉┉┉

题意:每条边上都有一个权值,表示这条边上最多运w重的物品,问从1到n一次最多能运多重的物品

思路:其实就是求从1到n的路上的最短边的最大值

考虑最短路的想法,dist[u]表示从1到u的最短边的最大值,当dist[v] < min(dist[u] , l[i].d)时,表示从u经过这条边到v,最短边的最大值要比直接到v大,所以更新dist[v]

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std;
#define SZ 1000010
#define INF 1e9+10
int head[SZ],nxt[SZ],tot = , n;
struct edge{
int t,d;
}l[SZ];
void build(int f,int t,int d){
l[++ tot] = (edge){t,d};
nxt[tot] = head[f];
head[f] = tot;
}
int dist[], vis[];
struct node
{
int u,d;
}now;
priority_queue<node> q;
bool operator < (node a, node b) {return a.d < b.d; }
int dij(int s, int e)
{
for(int i = ; i <= n; i++) dist[i] = , vis[i] = ;
while(q.size()) q.pop();
q.push((node){s,});
dist[s] = INF;
while(q.size())
{
int u = q.top().u;
q.pop();
if(vis[u]) continue;
vis[u] = ;
for(int i = head[u];i;i = nxt[i])
{
int v = l[i].t;
if(dist[v] < min(dist[u], l[i].d))
{
dist[v] = min(dist[u], l[i].d);
q.push((node){v,dist[v]});
}
}
}
return dist[e];
} int main()
{
int T, tt = ;
scanf("%d", &T);
while(T--)
{
int m;
scanf("%d %d", &n, &m);
tot = ;
memset(head, , sizeof(head));
memset(nxt, , sizeof(nxt));
while(m--)
{
int f, t, d;
scanf("%d %d %d", &f, &t, &d);
build(f, t, d);
build(t, f, d);
}
printf("Scenario #%d:\n", tt++);
printf("%d\n", dij(, n));
printf("\n");
}
return ;
}

最短路 || POJ 1797 Heavy Transportation的更多相关文章

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

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

  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 (Dijkstra变形)

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

  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 SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

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

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

  7. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  8. POJ 1797 Heavy Transportation (最短路)

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

  9. POJ 1797 Heavy Transportation (Dijkstra变形)

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

随机推荐

  1. 解决IIS中部署WCF时,访问.svc文件的404错误问题

    如果你直接在IIS 7中配置WCF,访问.svc文件时会出现404错误.解决方法,以管理员身份进入命令行模式,运行:"%windir%\Microsoft.NET\Framework\v3. ...

  2. ibatis 中 $与#的区别

    ibatis 中 $与#的区别 使用#: select * from table where id = #id# 如果字段为整型:#id#表示成id select * from table where ...

  3. 任务29:自己动手构建RequestDelegate管道

    cmd创建一个控制台应用程序 dotnet new console --name MyPipeline 用VSCode打开这个项目 新建类RequestDelegate.cs的类文件复制Program ...

  4. android调用第三方库——第一篇 (转载)

    转自:http://blog.csdn.net/jiuyueguang/article/details/9447245 版权声明:本文为博主原创文章,未经博主允许不得转载. 0:前言: 这两天一直在研 ...

  5. 两行代码搞定网站gzip压缩

    网站使用gzip压缩的好处就不用多说了吧,自行脑补,来说一下如何使用nodejs实现gzip压缩,只需要两行代码,so ease. 通过nodejs实现gzip 需要用到的模块 compression ...

  6. Cannot call value of non-function type 'UITextView'报错

    iOS里面的开发,类写到一半就报错这个.后来发现是因为重名的时候召唤对象不明确的问题.先贴代码,晚点再说 出错点 //ヒントをクリアするためのイニシャライザ init (clearStr: UITex ...

  7. 洛谷 - P2444 - 病毒 - AC自动机

    https://www.luogu.org/problemnew/show/P2444 有点恶心,不太明白fail的意义. #include<bits/stdc++.h> using na ...

  8. bzoj 1982: [Spoj 2021]Moving Pebbles【博弈论】

    必败状态是n为偶数并且数量相同的石子堆可以两两配对,因为这样后手可以模仿先手操作 其他状态一定可以由先手给后手一步拼出一个必败状态(用最大堆补) #include<iostream> #i ...

  9. fiddler安装及抓取http和https请求

    安装fiddler 安装完成,此时就可以抓取http请求了 如果要抓取https请求,就需要更新fiddler为最新版,并安装证书 1.检查更新fiddler为最新版 2.下载证书并安装 https证 ...

  10. [WOJ1583]向右看齐

    题目链接: WOJ1583 题目分析: 大水题--我就来水个题解 倒序扫,单调栈维护单减序列,每个对象的答案是栈里它下面那个元素 代码: #include<bits/stdc++.h> # ...