求(Dijkstra算法,求每条路径上的最小值 的最大值)和青蛙的那题类似;
 
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<algorithm>
#define INF 0xfffffff
#define N 1100
using namespace std; int n,m,dist[N],vis[N];
int maps[N][N]; void Init()
{
int i,j;
memset(vis,,sizeof(vis));
for(i=;i<=n;i++)
{
dist[i]=;
for(j=;j<=n;j++)
{
maps[i][j]=;
}
}
} void Dij(int Start,int End)
{
int Max,index,i,j;
dist[Start] = INF;
for(i = ; i <= n; i++)
{
index=-;
Max=;
for(j = ; j <= n; j++)
{
if(vis[j] == && Max < dist[j])
{
Max = dist[j];
index = j;
}
}
if(index == -)break;
vis[index] = ;
for(j = ; j <= n; j++)
{
if(vis[j] == &&dist[j] < min(dist[index],maps[index][j])) dist[j] = min(dist[index],maps[index][j]);
}
}
} int main()
{
int T,t=,a,b,c;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m); Init(); while(m--)
{
scanf("%d%d%d",&a,&b,&c); maps[a][b] = maps[b][a] = max(maps[a][b],c);
}
Dij(,n); printf("Scenario #%d:\n%d\n\n",t++,dist[n]);
}
return ;
}

下面是相当于求最大生成树的方法

#include <iostream>
#include <cstdio>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <queue>
#include <algorithm>
using namespace std;
#define N 1210
#define INF 0xfffffff int dist[N], maps[N][N], vis[N], n, ans;
void Dij(int s, int e)
{
for(int i=; i<=n; i++)
dist[i] = maps[s][i];
for(int i=; i<=n; i++)
{
int Max = , Index = -;
for(int j=; j<=n; j++)
{
if(vis[j]== && Max<dist[j])
{
Max = dist[j];
Index=j;
}
}
if(Index == -)break; vis[Index]=; ans=min(ans, dist[Index]); if(Index==n)return ; for(int j=; j<=n; j++)
{
if(vis[j]== && dist[j]<maps[Index][j])
dist[j] = maps[Index][j];
}
}
}
int main()
{
int T, t=, m, a, c, b;
scanf("%d", &T);
while(T--)
{
scanf("%d%d", &n, &m);
memset(vis, , sizeof(vis));
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
maps[i][j]=;
dist[i]=maps[i][i]=;
}
for(int i=; i<=m; i++)
{
scanf("%d%d%d", &a, &b, &c);
maps[a][b] = maps[b][a] = max(maps[a][b], c);
}
ans = INF;
Dij(, n);
printf("Scenario #%d:\n", t++);
printf("%d\n\n", ans);
}
return ;
}

Heavy Transportation---poj1797的更多相关文章

  1. (最短路) Heavy Transportation --POJ--1797

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

  2. POJ--1797 Heavy Transportation (最短路)

    题目电波: POJ--1797 Heavy Transportation n点m条边, 求1到n最短边最大的路径的最短边长度 改进dijikstra,dist[i]数组保存源点到i点的最短边最大的路径 ...

  3. POJ1797 Heavy Transportation 【Dijkstra】

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 21037   Accepted:  ...

  4. (Dijkstra) POJ1797 Heavy Transportation

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 53170   Accepted:  ...

  5. POJ1797:Heavy Transportation(改造Dijkstra)

    Heavy Transportation Time Limit: 3000MS   Memory Limit: 30000K Total Submissions: 52728   Accepted:  ...

  6. POJ1797 Heavy Transportation —— 最短路变形

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

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

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

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

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

  9. Heavy Transportation(最短路 + dp)

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

  10. POJ 1797 Heavy Transportation (Dijkstra变形)

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

随机推荐

  1. 用shell查找某目录下的最大文件

    这是一个很有趣的问题,因为作为一个shell菜鸟,我第一时间是没有任何想法的.心里纳闷为什么这样的操作Linux居然没有直接的命令实现这样的查询. 很自然地,第一感觉就是用awk去实现,因为菜鸟我看a ...

  2. MFC框架程序解析

    MFC的 程序框架: WinMain函数:程序首先到达全局变量theApp,再到达theAPP的构造函数,最后到达WinMain函数处. 问:为何要定义一个全局对象theAPP,让其在WinMain函 ...

  3. 《转载》Python3安装Scrapy

    运行平台:Windows Python版本:Python3.x IDE:Sublime text3 转载自:http://blog.csdn.net/c406495762/article/detail ...

  4. 【分布式系列之ActiveMq】ActiveMq入门示例

    前言 github地址:https://github.com/AndyFlower/web-back/tree/master/ActiveMq01 下载ActiveMQ :http://activem ...

  5. html2canvas - 项目中遇到的那些坑点汇总(更新中...)

    截图模糊    原理就是讲canvas画布的width和height放大两倍. 后来学习canvas的时候,才了解到这种写法不同于css的宽高设置, 因为css里的只是展示画布显示的大小,不像这样是c ...

  6. VC++生成不同的随机数

    其用法是先调用srand函数,如 srand( (unsigned)time( NULL ) ) 这样可以使得每次产生的随机数序列不同.假如计算伪随机序列的初始数值(称为种子)相同,则计算出来的伪随机 ...

  7. LeetCode 47 Permutations II(全排列)

    题目链接: https://leetcode.com/problems/permutations-ii/?tab=Description   给出数组,数组中的元素可能有重复,求出所有的全排列   使 ...

  8. [转]13 Hours: The Secret Soldiers of Benghazi

    转:http://www.imfdb.org/wiki/13_Hours:_The_Secret_Soldiers_of_Benghazi The following weapons were use ...

  9. MVC验证

    前言 MVC自己的验证机制,通过一个案例记录学习的成果. 首先,model代码如下: public class Students    {        [Display(Name = "I ...

  10. File类使用

    简介 File类的实例代表了一个文件或者一个目录,通过API可以获取这个对象的相关信息. File类代表的文件或者目录可以真实存在,也可以是不存在的,可以使用File.exists()来判断. 在Wi ...