最短路 || POJ 1797 Heavy Transportation
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
Output
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的更多相关文章
- poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
- POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
- POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
- POJ 1797 Heavy Transportation
题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ...
- 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、最短边最大化】
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 (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ 1797 Heavy Transportation (Dijkstra变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
随机推荐
- 【旧文章搬运】Windbg+Vmware驱动调试入门(二)---Vmware及GuestOS的设置
原文发表于百度空间,2009-01-08========================================================================== 这一篇是主 ...
- 【旧文章搬运】Windbg+Vmware驱动调试入门(一)---Windbg的设置
原文发表于百度空间,2009-01-08========================================================================== Windb ...
- oppo手机怎么打开USB调试模式
OPPO手机USB调试的设置方法:1.ColorOS 3.0版本,进入设置--关于手机,连续点击版本号直到出现“您已处于开发者选项”,再进入设置--其他设置--开发者选项--USB调试进行设置: 2. ...
- Hadoop Hive概念学习系列之HDFS、Hive、MySQL、Sqoop之间的数据导入导出(强烈建议去看)
Hive总结(七)Hive四种数据导入方式 (强烈建议去看) Hive几种数据导出方式 https://www.iteblog.com/archives/955 (强烈建议去看) 把MySQL里的数据 ...
- iOS UITextView 设置圆角边框线
textView.layer.borderColor = UIColor.lightGray.cgColor textView.layer.cornerRadius = 4 textView.laye ...
- django网页渲染
模板标签种类 {% for blog in blog_list %} <h2>{{ blog.title }}</h2> <p>{{ blog.timestamp ...
- python之重写父类方法
#修改父类的方法#重写父类的方法的目的是为了给他扩展功能,父类的方法已经不能满足需求#核心思想就一句话,先调用一下你要重写的父类方法,class Coon(object): #基本类 def __in ...
- Codeforces Round #261 (Div. 2) A
Description Pashmak has fallen in love with an attractive girl called Parmida since one year ago... ...
- 浅谈Java中static作用--转
static表示“全局”或者“静态”的意思,用来修饰成员变量和成员方法,也可以形成静态static代码块,但是Java语言中没有全局变量的概念. 被static修饰的成员变量和成员方法独立于该类的任何 ...
- iOS开发隐藏tabBar的问题
开发中遇到第一个页面需要显示tabBar,但是第二个页面不需要显示,当回到第一个页面的时候又需要显示的情况. 在第一个页面跳转到第二个页面的时候需要给第二个页面设置tabBar的隐藏 - (void) ...