Background 

Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a way from the place his customer has build his giant steel crane to the place where it is needed
on which all streets can carry the weight. 

Fortunately he already has a plan of the city with all streets and bridges and all the allowed weights.Unfortunately he has no idea how to find the the maximum weight capacity in order to tell his customer how heavy the crane may become. But you surely know. 

Problem 

You are given the plan of the city, described by the streets (with weight limits) between the crossings, which are numbered from 1 to n. Your task is to find the maximum weight that can be transported from crossing 1 (Hugo's place) to crossing n (the customer's
place). You may assume that there is at least one path. All streets can be travelled in both directions.

Input

The first line contains the number of scenarios (city plans). For each city the number n of street crossings (1 <= n <= 1000) and number m of streets are given on the first line. The following m lines contain triples of integers
specifying start and end crossing of the street and the maximum allowed weight, which is positive and not larger than 1000000. There will be at most one street between each pair of crossings.

Output

The output for every scenario begins with a line containing "Scenario #i:", where i is the number of the scenario starting at 1. Then print a single line containing the maximum allowed weight that Hugo can transport to the customer.
Terminate the output for the scenario with a blank line.

Sample Input

1
3 3
1 2 3
1 3 4
2 3 5

Sample Output

Scenario #1:
4

刚开始的思路是把每条边的权值处理一下 用1000005-w作为权值,然后求最短路 再求路径上的最小的那个权值

但是实际上每一次都要尽量找最大的那个权值 而不是让和最大

所以正确的做法是改变一下松弛的条件【最短路题目的核心】

然而还是不太清楚要怎么改 参考了一下题解

dijkstra 和 sfpa都写了下

还有就是 最短路的题目要注意初始化

这道题用cin会T

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<cstring>
#include<queue>
#include<stack>
#define inf 0x3f3f3f3f using namespace std; const int maxn = 1005;
int t, n, m;
bool vis[maxn];
int p[maxn][maxn], d[maxn]; /*void dijkstra(int sec)
{
int mmax, max_num;
for(int i = 1; i <= n; i++ ){
vis[i] = false;
d[i] = p[sec][i];
}
vis[sec] = true;
d[sec] = 0;
for(int i = 1; i < n; i++){
mmax = -inf;
for(int j = 1; j <= n; j++){
if(!vis[j] && d[j] > mmax){
mmax = d[j];
max_num = j;
}
}
vis[max_num] = 1;
for(int j = 1; j <= n; j++){
if(!vis[j] && d[j] < min(p[max_num][j], d[max_num])){
d[j] = min(p[max_num][j], d[max_num]);
}
}
}
}*/ void spfa(int sec)
{
queue <int> q;
for(int i = 1; i <= n; i++){
d[i] = -1;
vis[i] = false;
} d[sec] = inf;
vis[sec] = true;
q.push(sec);
while(!q.empty()){
int v = q.front();q.pop();
vis[v] = false;
for(int i = 1; i <= n; i++){
int t = min(d[v], p[v][i]);
if(d[i] < t){
d[i] = t;
if(!vis[i]){
vis[i] = true;
q.push(i);
}
}
}
}
} int main()
{
cin>>t;
for(int cas = 1; cas <= t; cas++){
memset(p, 0, sizeof(p));
scanf("%d%d",&n,&m);
for(int i = 0; i < m; i++){
int a, b, c;
scanf("%d%d%d",&a,&b,&c);
p[a][b] = c;
p[b][a] = c;
}
spfa(1); cout<<"Scenario #"<<cas<<":\n";
cout<<d[n]<<endl<<endl;
} return 0;
}

dijkstra的思路:

做n-1次遍历 每次都找还没访问的节点中d[]最大的那个节点j【起点到这个节点的路径中 最小权值的边 比起点到其他节点的路径中最小权值的边的权值要大】

遍历这个结点的邻接点,做松弛操作

如果这个邻接点 i 没有被访问过 如果他此时的d比   j 的 d 和 j 到 i 的边的权值的最小值要小   那么就要更新 i 的d【让起点到 i 的路径经过 j】

spfa的思路:

设置一个队列 将起点加入队列 每次从队列中取出队头    更新剩余结点

松弛条件和dijkstra类似

给边权值初始化为0, 这样他的权值比所有的d都要小, 也就不会赋值给任何的d了

POJ1797 Heavy Transpotation的更多相关文章

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

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

  2. POJ1797 Heavy Transportation 【Dijkstra】

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

  3. (Dijkstra) POJ1797 Heavy Transportation

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

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

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

  5. POJ1797 Heavy Transportation (堆优化的Dijkstra变形)

    Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand bus ...

  6. POJ1797 Heavy Transportation(SPFA)

    题目要求1到n点的最大容量的增广路. 听说是最短路求的,然后乱搞就A了.. 大概能从Bellman-Ford的思想,dk[u]表示从源点出发经过最多k条边到达u点的最短路,上理解正确性. #inclu ...

  7. poj1797 - Heavy Transportation(最大边,最短路变形spfa)

    题目大意: 给你以T, 代表T组测试数据,一个n代表有n个点, 一个m代表有m条边, 每条边有三个参数,a,b,c表示从a到b的这条路上最大的承受重量是c, 让你找出一条线路,要求出在这条线路上的最小 ...

  8. poj1797 Heavy Transportation Dijkstra算法的简单应用

    题目链接:http://poj.org/problem?id=1797 题目就是求所有可达路径的其中的最小值边权的最大值 即对于每一条能够到达的路径,其必然有其最小的承载(其实也就是他们自身的最大的承 ...

  9. POJ1797 Heavy Transportation

    解题思路:典型的Kruskal,不能用floyed(会超时),上代码: #include<cstdio> #include<cstring> #include<algor ...

随机推荐

  1. 2018年7月份,python上传自己的包库到pypi官网的方法

    最近pypi官网进行了更新,老的上传网址作废了.记录下上传到pypi的方法 0.去pypi官网注册账号,没账号是不可能上传的,想想也是那不乱套了吗,注册后会收到一个邮件需要点击然后重新登录 1.目录就 ...

  2. 8 -- 深入使用Spring -- 4...3 AOP的基本概念

    8.4.3 AOP的基本概念 AOP从程序运行角度考虑程序的流程,提取业务处理过程的切面.AOP面向的是程序运行中各个步骤,希望以更更好的方式来组合业务处理的各个步骤. AOP框架并不与特定的代码耦合 ...

  3. MongoDB管理

    前几篇文章都是从开发和使用的角度了解了MongoDB的各个知识点,这篇文章将从MongoDB管理的角度入手,了解MongoDB管理所要了解的基本知识. 数据库命令 在前面几篇文章中,已经接触了一些数据 ...

  4. linux 端口占用情况

    1,查看8010端口是否被占用 [root@cloud ~]# netstat -an|grep 8010 tcp 0 0 0.0.0.0:8010 0.0.0.0:* LISTEN 2,查看8010 ...

  5. PHP代码审计笔记--弱类型存在的安全问题

    0x01 前言 PHP 是一门弱类型语言,不必向 PHP 声明该变量的数据类型,PHP 会根据变量的值,自动把变量转换为正确的数据类型. 弱类型比较,是一个比较蛋疼的问题,如左侧为字符串,右侧为一个整 ...

  6. 基于端口的弱口令检测工具--iscan

    亲手打造了一款弱口令检测工具,用Python编写,主要可以用于内网渗透.弱口令检测等方面,目前集成了常见端口服务,包含 系统弱口令:ftp.ssh.telnet.ipc$ 数据库弱口令:mssql.m ...

  7. Linux 日常运维

    查看用户信息:w 查看系统负载:uptime 查看系统资源使用情况:vmstat 查看进程动态:top 查看网卡流量:sar 查看网卡流量:nload 查看磁盘读写:iostat 查看磁盘读写:iot ...

  8. CentOS7--TigerVNC

    --安装服务yum install tigervnc-server -y --配置文件,多个用户就拷贝多个cp /lib/systemd/system/vncserver@.service /etc/ ...

  9. android新建的项目界面上没有显示怎么办?

    看log也没有说明具体情况? 一翻折腾在清单文件里加了权限就好了!!!

  10. 把Model改成Lib

    1.把库的Activity删掉 2.把库的Application节点内容删掉 3.apply plugin:' 包名.library' 4.把ApplicationId去掉, 导入即可使用