luoguP1462通往奥格瑞玛的道路(二分答案+spfa)
题意
给出n个点m条边的无向图。
每条边有两个权值a,b;
问在保证从1到n的路径a权值和小于x时,路径上b权值最大值最小为多少。
(n≤10000,m≤50000,x≤1000000000)
题解
二分x,然后跑最短路判断。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
struct hhh{
int nxt,to,w;
}c[];
queue<int> q;
#pragma GCC optimize(2)
/*inline void write(int x)
{
if(x<0) putchar('-'),x=-x;
if(x>9) write(x/10);
putchar(x%10+'0');
}*/
int cnt,book[],ans,maxx,l,r,head[],dis[],n,m,b,w[],u,v,k;
bool flag;
inline void add(register int u,register int v,register int w){
cnt++;
c[cnt].w=w;
c[cnt].to=v;
c[cnt].nxt=head[u];
head[u]=cnt;
}
inline void spfa(register int ma){
while(!q.empty()){
register int u=q.front();
q.pop();
book[u]=;
for(register int i=head[u];i;i=c[i].nxt){
register int v=c[i].to;
if(!book[v]&&w[v]<=ma&&dis[v]>dis[u]+c[i].w&&dis[u]+c[i].w<=b){
dis[v]=dis[u]+c[i].w;
book[v]=;
q.push(v);
if(v==){
while(!q.empty())q.pop();
flag=true;
return;
}
}
}
}
}
/*inline int read()
{
register int q=0;
register int f=1;
char ch=getchar();
while(ch<'0'||ch>'9')
{
if(ch=='-') f=-1;
ch=getchar();
}
while(!(ch<'0'||ch>'9'))
{
q=q*10+ch-'0';
ch=getchar();
}
return q*f;
}*/
inline int read()
{
register int X=,w=;
char ch=;
while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
while(isdigit(ch)) X=(X<<)+(X<<)+(ch^),ch=getchar();
return w?-X:X;
} int main(){
n=read();m=read();b=read();
for(register int i=;i<=n;i++){
w[i]=read();
maxx=max(maxx,w[i]);
}
for(register int i=;i<=m;i++){
u=read(),v=read(),k=read();
if(u==v)continue;
add(u,v,k);
add(v,u,k);
}
for(register int i=;i<n;i++){
dis[i]=;
}
q.push(n);
book[n]=;
flag=false;
spfa();
if(!flag){
printf("AFK");
return ;
}
l=max(w[],w[n]);
r=maxx+;
while(l<=r){
for(register int i=;i<n;i++){
dis[i]=;
book[i]=;
}
flag=false;
int mid=(l+r)/;
q.push(n);
book[n]=;
spfa(mid);
if(flag)r=mid-;
else l=mid+;
ans=mid; }
printf("%d",l);
return ;
}
luoguP1462通往奥格瑞玛的道路(二分答案+spfa)的更多相关文章
- 洛谷P1462 通往奥格瑞玛的道路[二分答案 spfa 离散化]
题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...
- [Luogu P1462] 通往奥格瑞玛的道路 (二分答案+最短路径)
题面 传送门:https://www.luogu.org/problemnew/show/P1462 Solution 这道题如果去除掉经过城市的收费.那么就是裸的最短路 但是题目要求经过城市中最多的 ...
- 洛谷P1462通往奥格瑞玛的道路——二分答案最短路
题目:https://www.luogu.org/problemnew/show/P1462 最大值最小问题,二分答案. 代码如下: #include<iostream> #include ...
- Luogu P1462 通往奥格瑞玛的道路 二分答案+最短路
先二分答案,再跑最短路,跑的时候遇到 过路费超过二分的答案的 就不拿他更新最短路 #include<cstdio> #include<iostream> #include< ...
- P1462 通往奥格瑞玛的道路 (二分+最短路)
题目 P1462 通往奥格瑞玛的道路 给定\(n\)个点\(m\)条边,每个点上都有点权\(f[i]\),每条边上有边权,找一条道路,使边权和小于给定的数\(b\),并使最大点权最小. 解析 二分一下 ...
- [LuoguP1462]通往奥格瑞玛的道路($SPFA+$二分)
#\(\mathcal{\color{red}{Description}}\) \(Link\) 有一个图,求其在\(1-N\)的最短路小于一个给定值下,点权最大值的最小值. #\(\mathcal{ ...
- 洛谷 P1462 通往奥格瑞玛的道路——二分+spfa
上一波链接 https://www.luogu.org/problem/P1462 这道题我们考虑二分答案 然后每次跑一次spfa判断是否能够到达n点 tips:在不考虑负权边的前提下我们写最短路最好 ...
- [LuoguP1462]通往奥格瑞玛的道路
题目链接 题意简述:现在有一个图,每经过一个点就会交钱,走一条路就会扣血.在血量>0的前提下,要从1走到n点,并且要求路径上交钱的最大值最小. 解题思路:首先最大值最小,我们选择二分.目前有两个 ...
- 洛谷 P1462 通往奥格瑞玛的道路 二分 最短路
#include<cstdio> #include<queue> #include<cstring> #include<algorithm> using ...
随机推荐
- MHA+ProxySQL 读写分离高可用
文档结构如下: 1.ProxySQL说明 ProxySQL是mysql的一款中间件的产品,是灵活的mysql代理层,可以实现读写分离,支持query路由器的功能,支持动态指定sql进行缓存,支持动态加 ...
- 51nod 1098 最小方差 排序+前缀和+期望方差公式
题目: 题目要我们,在m个数中,选取n个数,求出这n个数的方差,求方差的最小值. 1.我们知道,方差是描述稳定程度的,所以肯定是着n个数越密集,方差越小. 所以我们给这m个数排个序,从连续的n个数中找 ...
- Xshell调整终端显示的最大行数(缓冲区)
1 选择会话,按顺序点击文件->属性 ,打开"会话属性"窗口 如下 在"会话属性"窗口中选择“终端” 修改缓冲区大小的值:其范围为0~2147483647 ...
- shell脚本执行的三种方式
(1) bash script_name 或 sh script_name 推荐使用此方法,script_name 不需要执行权限亦可执行. (2) path/script_name 或 ...
- Vue-cli 3.0 构建项目
Vue-cli是vue的一个脚手架,我们可以通过它来构建我们的前端项目 vue-cli3环境配置 //1. 安装nodeJS(已经集成npm) 首先需要安装node环境,可以直接到中文官网http:/ ...
- luogu P1365 WJMZBMR打osu! / Easy(期望DP)
题目背景 原 维护队列 参见P1903 题目描述 某一天WJMZBMR在打osu~~~但是他太弱逼了,有些地方完全靠运气:( 我们来简化一下这个游戏的规则 有nnn次点击要做,成功了就是o,失败了就是 ...
- python 中i++、逻辑表达式
参考链接:https://www.cnblogs.com/yupeng/p/3345946.html i++运算符 python中没有类似i++之类实现+1的运算符,但是有++i,+-i.之类的,他们 ...
- 【codeforces 65A】Harry Potter and Three Spells
[题目链接]:http://codeforces.com/problemset/problem/65/A [题意] 你有3种魔法; 1.可以将a单位的石头变成b单位的铅 2.可以将c单位的铅变成d单位 ...
- FZU 1980 AbOr's story
AbOr's story Time Limit: 1000ms Memory Limit: 32768KB This problem will be judged on FZU. Original I ...
- solr在windows下的安装及配置
solr在windows下的安装及配置 首先,solr是基于Java开发的,所以使用的话需要先进行java环境的配置,在Java环境配置好之后就可以去http://www.apache.org/dyn ...