Description
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.
#include<iostream>
#include<cstring>
#include<queue>
#include<vector>
#include<cstdio> #define min(a,b) (a<b ? a:b) using namespace std; const int INF=10e8;
const int MaxN=; struct Node
{
int v,val; Node(int _v=,int _val=):v(_v),val(_val) {}
bool operator < (const Node &a) const
{
return val<a.val;
}
}; struct Edge
{
int v,cost; Edge(int _v=,int _cost=):v(_v),cost(_cost) {}
}; vector <Edge> E[MaxN]; void Dijkstra(int lowcost[],int n,int start)
{
priority_queue <Node> que;
Node qtemp;
int len;
int u,v,cost; for(int i=;i<=n;++i)
{
lowcost[i]=;
}
lowcost[start]=INF; que.push(Node(start,INF)); while(!que.empty())
{
qtemp=que.top();
que.pop(); u=qtemp.v; len=E[u].size(); for(int i=;i<len;++i)
{
v=E[u][i].v;
cost=E[u][i].cost; if(min(cost,lowcost[u])>lowcost[v])
{
lowcost[v]=min(cost,lowcost[u]);
que.push(Node(v,lowcost[v]));
}
}
}
} inline void addEdge(int u,int v,int c)
{
E[u].push_back(Edge(v,c));
} int ans[MaxN]; int main()
{
// ios::sync_with_stdio(false); int N,M;
int a,b,c;
int T; scanf("%d",&T); for(int cas=;cas<=T;++cas)
{
scanf("%d %d",&N,&M); for(int i=;i<=N;++i)
E[i].clear(); for(int i=;i<=M;++i)
{
scanf("%d %d %d",&a,&b,&c); addEdge(a,b,c);
addEdge(b,a,c);
} Dijkstra(ans,N,); printf("Scenario #%d:\n",cas);
printf("%d\n\n",ans[N]);
} return ;
}
(简单) POJ 1797 Heavy Transportation,Dijkstra。的更多相关文章
-
POJ.1797 Heavy Transportation (Dijkstra变形)
POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...
-
POJ 1797 Heavy Transportation (Dijkstra)
题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...
-
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)
POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...
-
poj 1797 Heavy Transportation(最大生成树)
poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...
-
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变形)
F - Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & ...
-
POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】
Heavy Transportation Time Limit:3000MS Memory Limit:30000KB 64bit IO Format:%I64d & %I64 ...
-
POJ 1797 Heavy Transportation (dijkstra 最小边最大)
Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...
随机推荐
-
读<;<;领域驱动设计-软件核心复杂性应对之道>;>;有感
道可道,非常道. 名可名,非常名. 无名天地之始,有名万物之母. ---老子 关于标题 好久没写东西了,动笔的动机是看完了一本书,想写点总结性的东西,一是为了回顾一下梳理知识点,二是为了日后遗忘时能有 ...
-
滑动的Button
在介绍SwitchButton之前,先来看一下系统Button是如何实现的.源码如下: @RemoteView public class Button extends TextView { publi ...
-
Ubuntu 安装 Xfce4 桌面
sudo apt-get install xubuntu-desktop From: http://tieba.baidu.com/p/294762291
-
Python 3 数值计算
Python 3.4.3 (v3.4.3:9b73f1c3e601, Feb 24 2015, 22:43:06) [MSC v.1600 32 bit (Intel)] on win32Type & ...
-
Webbench网站压力测试
Webbench是有名的网站压力测试工具,能测试处在相同硬件上,不同服务的性能以及不同硬件上同一个服务的运行状况.webBech的标准测试可以向我们展示服务器的 两项 内容:每秒钟相应请求数和每秒 ...
-
L7,too late
words: parcel,包裹 detective,侦探 expect,期待 airfield,飞机起落的场地 guard,警戒,守卫,n precious,adj,珍贵的 stone,石头 exp ...
-
计算机网络--差错检测(帧检验序列FCS计算方法)
我们知道数据链路层广泛使用循环冗余检验CRC的检验技术 现在我们知道要发送的数据M=101001(长度为k=6) 在我们每次发送数据的时候需要在M后面添加一个N位的冗余码,一共发送(k+N)位数据 ...
-
python捕获Ctrl+C信号
我们希望当服务器接收到一个 SIGTERM 信号时能够自动关机,或者做一些善后的操作,以下是实现的方法 import signal # 自定义信号处理函数 def my_handler(signum, ...
-
java.util.LinkedHashMap cannot be cast to xxx 和 net.sf.ezmorph.bean.MorphDynaBean cannot be cast to xxx
java.util.LinkedHashMap cannot be cast to com.entity.Person 使用mybatis, resultMap映射的是实体类Person, 查询出来的 ...
-
解决FileInputStream读取文本时 最后端会多出字符问题
使用 read(byte[]) 方法读取文本的时候,要用 String str = new String(byte[],int offset,int len) 来将数组中的元素转换为String字符串 ...