题目: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. 在windows下进行linux开发:利用Vagrant+virtualbox(ShowDoc与mp3dish的作者)

    1,介绍Vagrant 我们做web开发的时候经常要安装各种本地测试环境,比如apache,php,mysql,redis等等.出于个人使用习惯,可能我们还是比较习惯用windows.虽然说在wind ...

  2. SDL介绍

    SDL(Simple DirectMedia Layer)是一套开放源代码的跨平台多媒体开发库,使用C语言写成.SDL提供了数种控制图像.声音.输出入的函数,让开发者只要用相同或是相似的代码就可以开发 ...

  3. poj2390

    #include <stdio.h> #include <stdlib.h> int main() { int r,m,y,i; scanf("%d %d %d&qu ...

  4. poj1658

    #include <stdio.h> #include <stdlib.h> int main() { int n; scanf("%d",&n); ...

  5. python socket理论知识

    一.socket理论: 发现一个很好的文章,一个高手写的,我也就不再做搬运工了,直接连接吧,对理论感兴趣的可以去看看! http://www.cnblogs.com/dolphinX/p/346054 ...

  6. Saiku如何固定查询结果table的表头和首列

    在使用saiku查询的时候,当“行”和“列”的维度内容过多时,在查看时只看到数据,不知道是什么数据,维度不清楚,得来回拖动滚动条才行,所以同事提出想要固定“表头”和“首列”. 在网上找了一些现成的插件 ...

  7. android-supporting-multiple-devices

    There are a few common questions asked whenever development begins on a new Android app. What assets ...

  8. xcode UIImageView创建、图片加载、 音频文件播放、 延迟调用

    代码创建 /** 创建UIImageView */ UIImageView * imageView=[[UIImageView alloc]init]; /** 设置尺寸位置 */ imageView ...

  9. JavaScript之<script>标签简介

    向html页面中插入JavaScrpt的主要方法,就是使用<script>元素,下面是Html 4.01为<script>定义的6个属性. 1.async:可选表示应该立即下载 ...

  10. 微信开发-Jssdk调用分享实例

    using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.IO ...