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. sharepoint服务器修改密码后出现HTTP Error 503

    HTTP Error 503   解决办法: 更改sharepoint 网站应用程序池标示后,更改标示重新输入管理员密码,问题解决!

  2. 018--python 函数参数、变量、前向引用、递归

    目录 一.python函数的定义 二.函数参数 三.全局变量和局部变量 四.前向引用 五.递归 一.python函数的定义 python函数是对程序逻辑进行结构化或过程化的一种方法 1 python中 ...

  3. 斯坦福CS231n—深度学习与计算机视觉----学习笔记 课时3

    课时3 计算机视觉历史回顾与介绍下 ImageNet有5000万张图片,全部都是人工清洗过得,标注了超过2万个分类. CS231n将聚焦于视觉识别问题,图像分类关注的是大图整体:物体检测告诉你东西具体 ...

  4. Android 实用技巧 --- 命令godir (转载)

    转自:http://blog.csdn.net/bigmarco/article/details/6995426 source build/envsetup.sh后可以使用很多android集成的sh ...

  5. Android中R.java丢失不见的解决方案

    最近在做android项目时,遇到报错情况,于是clean了一下,结果java类全都报错了,里面的R下有红线,我一找,发现R.java不见了,真是奇怪,如下图(这是解决以后的): 然后查看了一下Con ...

  6. 第十四篇 .NET高级技术之反射

    两个现实中的例子:1.B超:大家体检的时候大概都做过B超吧,B超可以透过肚皮探测到你内脏的生理情况.这是如何做到的呢?B超是B型超声波,它可以透过肚皮通过向你体内发射B型超声波,当超声波遇到内脏壁的时 ...

  7. LuoguP2700逐个击破【并查集/生成树/正难则反】By cellur925

    题目传送门 题目大意:给你一棵树,求把其中k个点相互隔离(不连通)所需要的边权代价. 这题我开始是想要求出把k个点联通的最小代价的,但后来发现还是实现起来比较困难,题解里貌似也没有这种做法,于是就鸽了 ...

  8. jQuery笔记之工具方法—Ajax 优化回调地狱

    在上一篇文我们说到了回调地狱不好的地方,今天我们看看怎么来优化它,让它可以运用到实际开发中. 什么是回调地狱?回调地狱就是一个函数里面嵌套了所有功能函数,然后缩略图形成一个三角形. 这样的代码可复用性 ...

  9. PostgreSQL - 转义字符

    转载至:postgresql字符转义 前言 在PostgreSQL 9之前的版本中,可以直接使用反斜杠\进行转义:比如:\b表示退格, \n表示换行, \t表示水平制表符,\r标示回车,\f表示换页. ...

  10. Oracle之Char VarChar VarChar2

    Oracle之Char VarChar VarChar2 在Oracle数据库中,字符类型有Char.VarChar和VarChar2三种类型,但不大清楚各自区别在哪儿,平时基本上就是用VarChar ...