题目: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. 11417 - GCD

    Problem A GCD Input: Standard Input Output: Standard Output Given the value of N, you will have to f ...

  2. perl 升级到5.20版本

    不建议先rm 先下载tar.gz ...然後手动安装..default 安装到/usr/local/目录下.. 然後修改/usr/bin/perl的symbolic link到/usr/local/b ...

  3. 使用AFNetworking请求新浪微博数据接口出错解决办法

    在使用AFNetworking请求新浪微博数据接口时会出这样的错误,如 这样的错误说明,AFNetworking无法处理这样的数据格式.所以,我们需要修改AFNetworking中的一些接收数据格式. ...

  4. leetcode 刷题之路 64 Construct Binary Tree from Inorder and Postorder Traversal

    Given inorder and postorder traversal of a tree, construct the binary tree. Note: You may assume tha ...

  5. 关于ECMAScript6一些知识

    ECMAScript 是当前 JavaScript 语言规范的最新标准,一般称为 es6, 但是因为 该标准规范是在 2015年6月份发布的,所以也叫作 ECMAScript 2015 let 变量声 ...

  6. sql server把一个表中数据复制到另一个表

    insert into A(ID,Name,Sex,Address,DID,...) from (select ID,Name,Sex,Address, 5 DID)

  7. Oracle分析函数之开窗子句-即WINDOWING子句

    Oracle的分析函数,对我们进行统计有很大的帮助,可以避免一些子查询等操作,在统计中,我们对开窗函数的接触较少,下面主要介绍下开窗函数的使用; http://www.itpub.net/thread ...

  8. CLLocation

    http://blog.sina.com.cn/s/blog_9e8867eb01013knc.html 这家伙写的不错本人也参考了这篇博客,希望原文博主可以谅解新手的无奈举措 首相要提到的类是 CL ...

  9. realloc,c语言

    realloc #include <stdlib.h> main() { char* ptr=NULL; char* ptr2=NULL; ptr = malloc(); printf(& ...

  10. BZOJ 1415: [Noi2005]聪聪和可可( 最短路 + 期望dp )

    用最短路暴力搞出s(i, j)表示聪聪在i, 可可在j处时聪聪会走的路线. 然后就可以dp了, dp(i, j) = [ dp(s(s(i,j), j), j) + Σdp(s(s(i,j), j), ...