POJ.1797 Heavy Transportation (Dijkstra变形)

题意分析

  1. 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d,求从1到n的所有通路中,所能经过的的最大重量的车为多少。
  2. 2.

代码总览

#include <cstdio>
#include <cstring>
#include <algorithm>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#define nmax 1005
#define inf 1e8+7
using namespace std;
int t,n,m;
int mp[nmax][nmax];
int shortpath[nmax];
bool visit[nmax];
void dij(int s)
{
int cur = s;
memset(visit,0,sizeof(visit));
for(int i = 1;i<=n;++i){shortpath[i] = mp[cur][i];}
shortpath[cur] = 0;
visit[cur] = true;
for(int i = 1;i<=n-1 ;++i){
int minL = 0;
for(int j = 1;j<=n;++j){
if(!visit[j] && shortpath[j] != 0 && shortpath[j] >minL){
minL = shortpath[j];
cur = j;
}
}
visit[cur] = true;
for(int j = 1;j<=n;++j){
if(!visit[j]){
shortpath[j] = max(min(mp[cur][j],shortpath[cur]),shortpath[j]);
}
}
}
}
void init()
{
scanf("%d %d",&n,&m);
for(int i = 1;i<=n;++i)
for(int j = 1;j<=n;++j)
mp[i][j] = 0;
for(int i = 1;i<=m;++i){
int sta,end,dis;
scanf("%d %d %d",&sta,&end,&dis);
mp[sta][end] = mp[end][sta] = dis;
}
}
int main()
{
//freopen("in.txt","r",stdin);
int kase = 1;
scanf("%d",&t);
for(int i = 1;i<=t;++i){
init();
dij(1);
printf("Scenario #%d:\n",kase++);
printf("%d\n\n",shortpath[n]);
}
return 0;
}

POJ.1797 Heavy Transportation (Dijkstra变形)的更多相关文章

  1. POJ 1797 Heavy Transportation SPFA变形

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

  2. POJ 1797 Heavy Transportation (Dijkstra)

    题目链接:POJ 1797 Description Background Hugo Heavy is happy. After the breakdown of the Cargolifter pro ...

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

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

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

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

  5. POJ 1797 Heavy Transportation

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

  6. POJ 1797 Heavy Transportation (Dijkstra变形)

    F - Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & ...

  7. POJ 1797 ——Heavy Transportation——————【最短路、Dijkstra、最短边最大化】

    Heavy Transportation Time Limit:3000MS     Memory Limit:30000KB     64bit IO Format:%I64d & %I64 ...

  8. POJ 1797 Heavy Transportation(最大生成树/最短路变形)

    传送门 Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 31882   Accept ...

  9. POJ 1797 Heavy Transportation (dijkstra 最小边最大)

    Heavy Transportation 题目链接: http://acm.hust.edu.cn/vjudge/contest/66569#problem/A Description Backgro ...

随机推荐

  1. memory引擎和innodb引擎速度对比

    ysql> insert into innodb_test (name) select name from innodb_test; Query OK, rows affected ( min ...

  2. 「Python」Numpy equivalent of MATLAB's cell array

    转自Stackoverflow.备忘用. Question I want to create a MATLAB-like cell array in Numpy. How can I accompli ...

  3. UniMelb Comp30022 IT Project (Capstone) - 1.Android入门

    1. Android入门 Android系统架构 Android系统:四层架构.五块区域 1. Linux内核层 Linux Kernel:为Android设备的硬件提供了底层驱动 2. 系统运行库层 ...

  4. [leetcode-667-Beautiful Arrangement II]

    Given two integers n and k, you need to construct a list which contains n different positive integer ...

  5. HDU 2491 Priest John's Busiest Day(贪心)(2008 Asia Regional Beijing)

    Description John is the only priest in his town. October 26th is the John's busiest day in a year be ...

  6. c# byte[] 保存图片

    1.用函数即可,File.WriteAllBytes(@"E:\123.bmp", pcBMPBuffer); 2.byte[]也可和image互相转化.

  7. bootstrap使用中遇到的坑

    一.例如: <div class="form-group"> <label class="control-label col-lg-3"> ...

  8. lintcode-149-买卖股票的最佳时机

    149-买卖股票的最佳时机 假设有一个数组,它的第i个元素是一支给定的股票在第i天的价格.如果你最多只允许完成一次交易(例如,一次买卖股票),设计一个算法来找出最大利润. 样例 给出一个数组样例 [3 ...

  9. DDB与DIB

    DB与DIB的区别是什么?觉得书上介绍的有点抽象.不容易理解.他们两者之间的区别的“物理意义” [“现实意义”]——姑且这么叫吧,呵呵!被这个问题困扰了很久,所以今天决定好好查资料总结一下,把它彻底搞 ...

  10. 活学活用wxPython

    http://www.czug.org/python/wxpythoninaction/