POJ 1797 Heavy Transportation 最短路变形(dijkstra算法)
题目: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算法)的更多相关文章
- poj 1797 Heavy Transportation(Dijkstar变形)
http://poj.org/problem?id=1797 给定n个点,及m条边的最大负载,求顶点1到顶点n的最大载重量. 用Dijkstra算法解之,只是需要把“最短路”的定义稍微改变一下, A到 ...
- POJ 1797 Heavy Transportation (最短路)
Heavy Transportation Time Limit: 3000MS Memory Limit: 30000K Total Submissions: 22440 Accepted: ...
- POJ 1797 Heavy Transprotation ( 最短路变形 || 最小生成树 )
题意 : 找出 1 到 N 点的所有路径当中拥有最大承载量的一条路,输出这个最大承载量!而每一条路的最大承载量由拥有最大承载量的那一条边决定 分析 : 与 POJ 2253 相似且求的东西正好相反,属 ...
- 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 ...
- POJ1797 Heavy Transportation —— 最短路变形
题目链接: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 ...
随机推荐
- XCode破解真机调试
XCode破解真机调试 3.0 一.这样做以后能怎样 以device模式编译出app 可以再越狱后的设备上运行 二.要会点什么 命令行,也就是terminal.终端.控制台... vim 三.开始吧 ...
- Gdal 1.11.0 添加 Postgresql 9.1 sqlite3 支持
OS环境Ubuntu12.04 32bit 因为公司一个功能要用到gdal 的ogr2ogr命令转换shp数据,需要能往postgis和sqlite 中插入数据. 用gdal1.11.0的源码默认安装 ...
- js模块化认识1
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Sequence operation(线段树区间多种操作)
Sequence operation Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Othe ...
- Linux下安装Oracle的过程和涉及的知识点-系列4
10.使用rpm安装包 假设本地有现成的相关包,能够直接使用rpm安装.rpm rpm包名,但有时会出现它须要其他包的支持,这时若须要忽略此提示.强行安装,运行rpm -i --force --nod ...
- 如何获取启动文件路径 GetModuleFileName
如何获取启动文件路径 GetModuleFileName CString GetExeDirPath() { }; CString strExeDirPath; GetModuleFileName(N ...
- eclipse开发工具Import工程后,工程文件夹上出现黄色感叹号——解决方法
eclipse开发工具Import工程后,工程文件夹上出现黄色感叹号. 可能是Work目录无效,解决方法:删除Work目录即可,如下图所示: 删除后,如下图:
- Unity StrangeIoc框架 (三)signal信号方式
先创建TestRoot using UnityEngine; using System.Collections; using strange.extensions.context.impl; publ ...
- B - 确定比赛名次
B - 确定比赛名次 Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit S ...
- Spark源码学习2
转自:http://www.cnblogs.com/hseagle/p/3673123.html 在源码阅读时,需要重点把握以下两大主线. 静态view 即 RDD, transformation a ...