题目传送门

题意:求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的更多相关文章

  1. POJ.1797 Heavy Transportation (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  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(最大生成树)

    poj 1797 Heavy Transportation Description Background Hugo Heavy is happy. After the breakdown of the ...

  4. POJ 1797 Heavy Transportation SPFA变形

    原题链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  5. POJ 1797 Heavy Transportation

    题目链接:http://poj.org/problem?id=1797 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K T ...

  6. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  7. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  8. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

  9. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

随机推荐

  1. windows端口备忘

    FTP 端口号21 SSH 端口号22 Telnet 端口号23

  2. html+css+js实现标签页切换

    CSS部分: #Tab { margin:0 auto; width:640px; border:none; position:absolute; z-index:9; margin-left:320 ...

  3. Android开发环境搭建:离线安装ADT插件和安装SDK

    一.准备 在线安装SDK较慢,在此我选择了离线安装,所需要的工具下载:http://yun.baidu.com/share/link?shareid=2286446004&uk=2000812 ...

  4. [转] C++的STL库,vector sort排序时间复杂度 及常见容器比较

    http://www.169it.com/article/3215620760.html http://www.cnblogs.com/sharpfeng/archive/2012/09/18/269 ...

  5. NYOJ题目1047欧几里得

    aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAskAAAIcCAIAAACLpKQmAAAgAElEQVR4nO3dv1LjOsMH4O8m6LkQ6l ...

  6. Hibernate项目用Maven创建(转)

    本文将用Maven3.Hibernate3.6.Oracle10g整合,作为例子. 环境清单: 1.Maven3.0.5 2.Hibernate3.6.5 Final 3.JDK1.7.0.11 4. ...

  7. iOS开发Xcode7真机调试教程

    从Xcode7开始,Xcode 不需要$99/$299升级开发者直接可以进行真机调试 调试步骤 1.假设已经你已经有了苹果账号,下载并安装好了Xcode7 2. 打开Xcode-> Prefer ...

  8. 快速反编绎jar war包

    反编译这些class文件或jar包或war包,用TTools https://github.com/Supermax197/TTools [root@ok action]# tree /home/ok ...

  9. mysql 源码安装

    yum install -y gcc gcc-c++ autoconf libjpeg libjpeg-devel perl perl-CPAN libpng libpng-devel freetyp ...

  10. MyBatis 特殊字符处理

    http://blog.csdn.net/zheng0518/article/details/10449549