题目:click here

题意:

  有n个城市,m条道路,在每条道路上有一个承载量,现在要求从1到n城市最大承载量,而最大承载量就是从城市1到城市n所有通路上的最大承载量。
分析:

  其实这个求最大边可以近似于求最短路,只要修改下找最短路更新的条件就可以了。

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string> using namespace std;
const int INF = 1e9+;
const int M = 1e3+; int t, n, m;
int f, too, c;
int d[M];
int cost[M][M]; // 邻接矩阵
bool vis[M]; void dijkstra( int s ) { // 戴克斯特拉算法
memset( vis, false, sizeof(vis) );
for ( int i=; i<=n; i++ )
d[i] = cost[][i];
int tm = n;
vis[s] = true;
while( tm-- ) {
int minn = -INF, k;
for( int i=; i<=n; i++ ) {
if( !vis[i] && d[i] > minn ) {
minn = d[i];
k = i;
}
}
vis[k] = true;
for( int j=; j<=n; j++ ) {
if( !vis[j] && d[j] < min( d[k], cost[k][j] ) )
d[j] = min( d[k], cost[k][j] );
}
}
} void solve() {
scanf("%d%d", &n, &m );
for( int i=; i<=n; i++ ) {
for( int j=; j<=n; j++ )
cost[i][j] = ;
}
for( int i=; i<=m; i++ ) {
scanf("%d%d%d", &f, &too, &c );
cost[f][too] = c;
cost[too][f] = c;
}
dijkstra( );
printf("%d\n", d[n] );
} int main() {
while( ~scanf("%d", &t ) ) {
for( int tcase=; tcase<=t; tcase++ ) {
printf("Scenario #%d:\n", tcase );
solve();
printf("\n"); // 注意格式最后有一个空行
}
}
return ;
}

POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)的更多相关文章

  1. poj 1797 Heavy Transportation(Dijkstar变形)

    http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...

  2. POJ 1797 Heavy Transportation (最短路)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 22440   Accepted:  ...

  3. POJ 1797 Heavy Transprotation ( 最短路变形 || 最小生成树 )

    题意 : 找出 1 到 N 点的所有路径当中拥有最大承载量的一条路,输出这个最大承载量!而每一条路的最大承载量由拥有最大承载量的那一条边决定 分析 : 与 POJ 2253 相似且求的东西正好相反,属 ...

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

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

  5. POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径)

    POJ 1797 Heavy Transportation / SCU 1819 Heavy Transportation (图论,最短路径) Description Background Hugo ...

  6. poj 1797 Heavy Transportation(最大生成树)

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

  7. POJ 1797 Heavy Transportation SPFA变形

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

  8. POJ1797 Heavy Transportation —— 最短路变形

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

  9. POJ 1797 Heavy Transportation

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

随机推荐

  1. 细说javascript函数

    javascript函数是一个比较奇怪的东西,接触一段时间你就会犯迷糊,弄不明白它到底是什么了.你是否会因为有的javascript函数没有名字而莫名其妙,是否会因为javascript函数的参数没有 ...

  2. CentOS7 vs centos6

    The CentOS Project has announced general availability of CentOS-7, the first release of the free Lin ...

  3. 十几个remote control software

    5 alternatives to LogMeIn Free for remote PC access VNC VNC, or Virtual Network Computing, isn’t its ...

  4. Unix/Linux环境C编程入门教程(10) SUSE Linux EnterpriseCCPP开发环境搭建

    安装SUSE企业版以及搭建C/C++开发环境 1.      SUSELinux Enterprise是一款服务器操作系统,异常稳定. 2.设置虚拟机类型. 3.选择稍后安装操作系统. 4.选择SUS ...

  5. golang仿AS3写的ByteArray

    用golang写了个仿AS3写的ByteArray,稍微有点差别,demo能成功运行,还未进行其他测试 主要参考的是golang自带库里的Buffer,结合了binary 来看看demo: packa ...

  6. poj2578---三个数中找出第一个大于168的

    #include <stdio.h> #include <stdlib.h> int main() { int a,b,c; scanf("%d %d %d" ...

  7. IOS深入学习(3)之Control Object

    1 前言 今天我们来简单的学习一下IOS中用户点击屏幕后的事件处理,其中主要介绍一下Control Object,内容如下. 2 详述 Control是处于当用户用某种方式操作进行发送消息给另一个界面 ...

  8. 【转】Ubuntu Linux 下文件名乱码(无效的编码)的快速解决办法

    原博文地址:http://www.cnblogs.com/york-hust/archive/2012/07/07/2580388.html 文件是在WIndows 下创建的,Windows 的文件名 ...

  9. ubuntu FTP服务安装

    //安装vsftp apt-get install vsftpd -y //增加账号 //1 查找 nologin位置 /usr/sbin/nologin useradd -d /alidata/ww ...

  10. jQuery 迭代器

    在 叶小钗 的博客中看到一段关于遍历的代码 var ajQuery = {}; function dir(elem, dir, until) { var matched = [], truncate ...