题目链接:http://poj.org/problem?id=1797

题意:n个城镇,m条路上能承载的最大重量。现在问你从1到n的最大承重量。

题解:spfa的变体。

假设当前1->当前点的承载量是d[v] 比 从1->k的承载量d[now] 小 或者 是比当前的承载量e[now][i].second小,就更新。

然后注意一下初始化的时候d[]的大小。具体的看代码吧。QWQ板子好用。

代码:

 #include<iostream>
#include<stack>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int maxn = 2e5+; vector< pair<int,int> > e[maxn]; int n,m;
int d[maxn],inq[maxn]; void init(){
for(int i = ; i < maxn; i++)
e[i].clear();
for(int i = ;i < maxn ; i++)
inq[i] = ;
for(int i = ; i < maxn ; i++)
d[i] = ;
} int main() {
int T;
cin>>T;
int cas = ;
while(T--){
cin>>n>>m;
init();
int x,y,z;
for(int i = ; i < m ;i++){
cin>>x>>y>>z;
e[x].push_back(make_pair(y,z));
e[y].push_back(make_pair(x,z));
}
int s,t;
//cin>>s>>t;
s = ;
t = n;
queue<int>Q;
Q.push(s);
d[s] = 1e9 ; //比小的话就初始化最大。
inq[s] = ;
while( !Q.empty() ){
int now = Q.front();
Q.pop();
inq[now] = ;
for(int i = ; i < e[now].size() ; i++){
int v = e[now][i].first;
//改。
if(d[v] < min( d[now] , e[now][i].second)){
d[v] = min(d[now] , e[now][i].second);
if(!inq[v]){
inq[v] = ;
Q.push(v);
continue;
}
}
} }
printf("Scenario #%d:\n",cas++);
cout<<d[t]<<endl;
cout<<endl;
}
return ;
}

【POJ】1797 Heavy Transportation的更多相关文章

  1. POJ 1797 Heavy Transportation

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

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

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

  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 (Dijkstra变形)

    POJ.1797 Heavy Transportation (Dijkstra变形) 题意分析 给出n个点,m条边的城市网络,其中 x y d 代表由x到y(或由y到x)的公路所能承受的最大重量为d, ...

  5. POJ 1797 Heavy Transportation SPFA变形

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

  6. 【POJ】1704 Georgia and Bob(Staircase Nim)

    Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, ...

  7. 【POJ】1067 取石子游戏(博弈论)

    Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的石子.最后 ...

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

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

  9. POJ 1797 Heavy Transportation (Dijkstra变形)

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

随机推荐

  1. win7 cmd 常用命令

    进入不同的分区  d: 查看之栏目树:tree 查看当前目录下的子目录:dir 切换不同的目录:cd

  2. Sql生成 Insert 语句

    declare @TableName sysname select @TableName = 'T_OOSOrder' declare @result varchar(max) = 'INSERT I ...

  3. 3、第一个Appium测试

    运行脚本前环境准备: 1.IDE,推荐使用IJ 2.安装jdk环境,推荐>1.8 3.准备一台真机或者模拟器 4.SDK 5.maven环境 项目目录: CalculatorTest.java文 ...

  4. 词表征 3:GloVe、fastText、评价词向量、重新训练词向量

    原文地址:https://www.jianshu.com/p/ca2272addeb0 (四)GloVe GloVe本质是加权最小二乘回归模型,引入了共现概率矩阵. 1.基本思想 GloVe模型的目标 ...

  5. 洛谷 P2756 飞行员配对方案问题 (二分图匹配)

    题目链接:P2756 飞行员配对方案问题 题意 给定 \(m\) 个外籍飞行员和 \(n - m\) 个英国飞行员,每一架飞机需要一名英国飞行员和一名外籍飞行员,求最多能派出几架飞机. 思路 最大流 ...

  6. PAT_A1139#First Contact

    Source: PAT A1139 First Contact (30 分) Description: Unlike in nowadays, the way that boys and girls ...

  7. kafka单机版的安装、集群部署 及使用

    1.安装kafka(单机版) 1.1上传 kafka_2.11-2.0.0.tgz 到 /root/Downloads 1.2解压 tar 包 tar -zxvf kafka_2.11-2.0.0.t ...

  8. ps--窗口配置

    移动工具设置 v 选择图层自动选择不勾 图层ctrl + 左键 视图设置智能参考线标尺 Ctrl+r 窗口设置 关闭 库 颜色 打开 信息 字符 图层 历史记录 信息 面板选项 鼠标单位 像素 rgb ...

  9. Javascript原型对象中的toString

    <script> //tostring function Person(name,age,gender){ this.name=name; this.age=age; this.gende ...

  10. 内网端口转发[SSH]

    一.应用场景 获取到目标边界机器linux服务器一台,想继而向内网其他机器渗透,获取到一台webshell发现处于内网当中且不通外网.可以通过linux ssh隧道对目标内网机器进行访问. 二.利用手 ...