(简单) POJ 1797 Heavy Transportation,Dijkstra。
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 ...
随机推荐
- 实测switch支持的参数类型
@Test public void testSwitch() { switch (2) { case 1: System.out.println("int型:" + 1); bre ...
- Jdk1.7环境变量的配置
在"系统属性——高级——环境变量——系统变量"中新建如下变量: 变量名:JAVA_HOME 变量值:C:\Program Files\Java\jdk1.7.0_03 (即jdk ...
- ==和equals的异同
== 和 Equals 的区别 1. == 是一个运算符. 2.Equals则是string对象的方法,可以.(点)出来. 我们比较无非就是这两种 1.基本数据类型比较 2.引用对象比较 1.基本数据 ...
- Amoeba for MySQL
Amoeba for MySQL Amoeba for MySQL致力于MySQL的分布式数据库前端代理层,它主要在应用层访问MySQL的时候充当query 路由功能,专注 分布式数据库 proxy ...
- Linux设置某软件开机自动启动的方法
方法一 将启动命令写到系统启动时会自动调用的脚本中 echo "/usr/local/apache2/bin/apachectl start" >> /etc/rc.d ...
- PAT (Advanced Level) 1111. Online Map (30)
预处理出最短路再进行暴力dfs求答案会比较好.直接dfs效率太低. #include<cstdio> #include<cstring> #include<cmath&g ...
- PAT (Advanced Level) 1102. Invert a Binary Tree (25)
简单题. #include<cstdio> #include<cstring> #include<cmath> #include<vector> #in ...
- [转]修改hosts文件不起作用
http://wayne173.iteye.com/blog/1876565 今天遇到个很奇怪的问题,在hosts文件里添加了一些域名指向后,发现根本没起作用,后来还发现个细节,就是hosts文件左下 ...
- 【spring boot】SpringBoot初学(2) - properties配置和读取
前言 只是简单的properties配置学习,修改部分"约定"改为自定义"配置".真正使用和遇到问题是在细看. 一.主要 核心只是demo中的: @Proper ...
- linux下如何修改iptables开启80端口
linux下如何修改iptables开启80端口 最近在做本地服务器的环境,发现网站localhost能正常访问,用ip访问就访问不了,经常使用CentOS的朋友,可能会遇到和我一样的问题.开启了 ...