Dijkstra(变形) POJ 1797 Heavy Transportation
题意:求1到n的最大载重量
分析:那么就是最大路上的最小的边权值,改变优先规则.
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
using namespace std; typedef long long ll;
const int N = 1e3 + 10;
const int E = 1e5 + 10;
const int INF = 0x3f3f3f3f;
struct Edge {
int v, w, nex;
Edge() {}
Edge(int v, int w, int nex) : v (v), w (w), nex (nex) {}
bool operator < (const Edge &r) const {
return w < r.w;
}
}edge[E];
int head[N];
int d[N];
bool vis[N];
int n, m, e; void init(void) {
memset (head, -1, sizeof (head));
e = 0;
} void add_edge(int u, int v, int w) {
edge[e] = Edge (v, w, head[u]);
head[u] = e++;
} void Dijkstra(int s) {
memset (d, 0, sizeof (d));
memset (vis, false, sizeof (vis));
d[s] = INF;
priority_queue<Edge> que; que.push (Edge (s, 0, 0));
while (!que.empty ()) {
int u = que.top ().v; que.pop ();
if (vis[u]) continue;
vis[u] = true;
for (int i=head[u]; ~i; i=edge[i].nex) {
int v = edge[i].v, w = edge[i].w;
if (!vis[v] && d[v] < min (d[u], w)) {
d[v] = min (d[u], w); que.push (Edge (v, d[v], 0));
}
}
}
} int main(void) {
int T, cas = 0; scanf ("%d", &T);
while (T--) {
init ();
scanf ("%d%d", &n, &m);
int mx = 0;
for (int u, v, w, i=1; i<=m; ++i) {
scanf ("%d%d%d", &u, &v, &w);
if (n == 1 && u == 1 && v == 1) mx = max (mx, w);
add_edge (u, v, w);
add_edge (v, u, w);
}
printf ("Scenario #%d:\n", ++cas);
if (n == 1) {
printf ("%d\n", mx); continue;
}
Dijkstra (1);
printf ("%d\n\n", d[n]);
} return 0;
}
Dijkstra(变形) POJ 1797 Heavy Transportation的更多相关文章
- POJ.1797 Heavy Transportation (Dijkstra变形)
		POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ... 
- 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 SPFA变形
		原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K T ... 
- POJ 1797 Heavy Transportation
		题目链接: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)
		题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ... 
- POJ 1797 Heavy Transportation(最大生成树/最短路变形)
		传送门 Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 31882 Accept ... 
随机推荐
- Web上的支持的图片格式以及它们之间的区别
			一.GIF(图形交换格式) GIF格式的图片最多只能保存256中颜色,该格式支持透明色,支持动画效果. 二.JPEG(联合图像专家组) JPEG格式不支持透明色及动画,颜色可达1670种. 三.PNG ... 
- DB2 bind on z/os
			BIND and REBIND options for packages and plans There are several options you can use for binding or ... 
- Loadrunner中Throughput(吞吐量)的分析与计算
			Throughput翻译为吞吐量,按照常规理解网络吞吐量表示在单位时间内通过网卡数据量之和,其中即包括本机网卡发送出去的数据量也包括本机网卡接收到的数据量,但这个理解在Loadrunner记录的Thr ... 
- linux中who命令显示的tty、pts和(:0)(:0.0)是什么意思
			http://blog.csdn.net/cwj_beyond/article/details/6987345 http://unix.stackexchange.com/questions/7217 ... 
- oracle数据库出现“批处理中出现错误: ORA-00001: 违反唯一约束条件”解决方法
			最近使用oraclede impdp工具全库导入数据库时,在数据库里面使用出现如下情况. SQL state : 违反唯一约束条件 (GDXAORCL.SYS_C0055359) ; nested e ... 
- poj 3468:A Simple Problem with Integers(线段树,区间修改求和)
			A Simple Problem with Integers Time Limit: 5000MS Memory Limit: 131072K Total Submissions: 58269 ... 
- blender源代码编译
			blender源码路径(svn):https://svn.blender.org/svnroot/bf-blender/trunk/blender/ 依赖外部Lib(svn):https://svn. ... 
- SQL Server 2014 BI新特性(一)五个关键点带你了解Excel下的Data Explorer
			Data Explorer是即将发布的SQL Server 2014里的一个新特性,借助这个特性讲使企业中的自助式的商业智能变得更加的灵活,从而也降低了商业智能的门槛. 此文是在微软商业智能官方博客里 ... 
- ASP.NET 自定义URL重写                                                    分类:            ASP.NET             2014-10-31 16:05    174人阅读    评论(0)    收藏
			一.功能说明: 可以解决类似 http://****/news 情形,Url路径支持正则匹配. 二.操作步骤: 1.增加URL重写模块: using System; using System.IO; ... 
- 如何安装sublime text2以及它的插件?
			下载Sublime Text2的安装包,安装,安装后打开的界面如图 下面我们来给他安装插件,首先安装packagecontrol,打开菜单栏中的View-->show console 在 ... 
