题目: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. Krita编译和旧版本下载

    Linux For Krita 2.9, David Revoy's guide Building Krita for Cats is the best available! Build Krita ...

  2. MyEclipse修改

    MyEclipse设置编码方式 http://www.cnblogs.com/susuyu/archive/2012/06/27/2566062.html Eclipse添加Spket插件实现ExtJ ...

  3. appium locator

    If you want to find out more about the UIAutomator library, then it might be helpful to check out ht ...

  4. You raise me up

    You raise me up, so I can stand on mountains;You raise me up, to walk on stormy seas;I am strong, wh ...

  5. 戏说Java多线程

    戏说Java多线程. package com.cmp.chengfu.app.jdk6.desktop; import java.awt.Desktop; import java.io.File; i ...

  6. Java基础之参数传递

    public class ArgsTransfer { /* * 基本数据类型直接存储在变量中,函数参数传递时,是将变量中存储的数据拷贝,函数中改变形参,和调用处的实参是不同的变量,两边互不影响 * ...

  7. HTML中小问题

    1.a标签不添加href这个属性时,不会出现鼠标变成手型~

  8. 学习笔记--C#特性Attribute(一)

    这个框框好烦人啊,删不掉 一.背景 [serializable] public class Person(){} 这是我第一次看到特性(Attribute),那时我还不知道这是什么,怎么会有这种写法, ...

  9. Tensorflow tflearn 编写RCNN

    两周多的努力总算写出了RCNN的代码,这段代码非常有意思,并且还顺带复习了几个Tensorflow应用方面的知识点,故特此总结下,带大家分享下经验.理论方面,RCNN的理论教程颇多,这里我不在做详尽说 ...

  10. 认识和理解css布局中的BFC

    认识和理解css布局中的BFC BFC的定义 是 W3C CSS 2.1 规范中的一个概念,它决定了元素如何对其内容进行定位,以及与其他元素的关系和相互作用. Block Formatting Con ...