题意

给出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)的更多相关文章

  1. 洛谷P1462 通往奥格瑞玛的道路[二分答案 spfa 离散化]

    题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...

  2. [Luogu P1462] 通往奥格瑞玛的道路 (二分答案+最短路径)

    题面 传送门:https://www.luogu.org/problemnew/show/P1462 Solution 这道题如果去除掉经过城市的收费.那么就是裸的最短路 但是题目要求经过城市中最多的 ...

  3. 洛谷P1462通往奥格瑞玛的道路——二分答案最短路

    题目:https://www.luogu.org/problemnew/show/P1462 最大值最小问题,二分答案. 代码如下: #include<iostream> #include ...

  4. Luogu P1462 通往奥格瑞玛的道路 二分答案+最短路

    先二分答案,再跑最短路,跑的时候遇到 过路费超过二分的答案的 就不拿他更新最短路 #include<cstdio> #include<iostream> #include< ...

  5. P1462 通往奥格瑞玛的道路 (二分+最短路)

    题目 P1462 通往奥格瑞玛的道路 给定\(n\)个点\(m\)条边,每个点上都有点权\(f[i]\),每条边上有边权,找一条道路,使边权和小于给定的数\(b\),并使最大点权最小. 解析 二分一下 ...

  6. [LuoguP1462]通往奥格瑞玛的道路($SPFA+$二分)

    #\(\mathcal{\color{red}{Description}}\) \(Link\) 有一个图,求其在\(1-N\)的最短路小于一个给定值下,点权最大值的最小值. #\(\mathcal{ ...

  7. 洛谷 P1462 通往奥格瑞玛的道路——二分+spfa

    上一波链接 https://www.luogu.org/problem/P1462 这道题我们考虑二分答案 然后每次跑一次spfa判断是否能够到达n点 tips:在不考虑负权边的前提下我们写最短路最好 ...

  8. [LuoguP1462]通往奥格瑞玛的道路

    题目链接 题意简述:现在有一个图,每经过一个点就会交钱,走一条路就会扣血.在血量>0的前提下,要从1走到n点,并且要求路径上交钱的最大值最小. 解题思路:首先最大值最小,我们选择二分.目前有两个 ...

  9. 洛谷 P1462 通往奥格瑞玛的道路 二分 最短路

    #include<cstdio> #include<queue> #include<cstring> #include<algorithm> using ...

随机推荐

  1. 《汇编语言(第三版)》pushf 和 popf 指令,以及标志寄存器在 Debug 中的表示

    pushf 和 popf pushf 的功能是将标志寄存器的值压栈,而 popf 是从栈中弹出数据,输入标志寄存器. pushf 和 popf,为直接访问寄存器提供了方法. 格式 pushf popf ...

  2. Ubuntu 16.04下安装64位谷歌Chromium(Chrome)浏览器

    在命令行下输入: sudo add-apt-repository ppa:a-v-shkop/chromium sudo apt-get update sudo apt-get install chr ...

  3. .NET深入解析LINQ框架1

    1.LINQ简述 2.LINQ优雅前奏的音符 2.1.隐式类型 (由编辑器自动根据表达式推断出对象的最终类型) 2.2.对象初始化器 (简化了对象的创建及初始化的过程) 2.3.Lambda表达式 ( ...

  4. 初识Git(二)

    与我们前一篇随笔一样创建文件夹,init我们创建的文件夹,并且创建一个test.txt文本文件,add文本文件,commit文本文件,接下来在文本文件中添加文本: 与上一次不同的是我们这一次在编辑文件 ...

  5. Dapper优秀资料

    dapper extensions (predicates) https://www.cnblogs.com/starluck/p/4542370.html

  6. 服务器搭建域控与SQL Server的AlwaysOn环境过程(三)配置故障转移

    0 引言 主要讲述如何搭建故障转移集群,因为AlwaysOn是基于Windows的故障转移集群的. 在讲解步骤之前需要了解一下故障转移集群仲裁配置 下面图片来自<Windows Server20 ...

  7. 向ueditor中插入内容

    html在ueditor中插入内容不能直接插入,必须判断编辑器是否创建成功,jsp可以用java代码嵌套的方式. html页面中:<textarea id="zym" nam ...

  8. python3 之 Ellipsis

    在翻django 代码的时候无意中看到的, 主要还是在注解时候使用 官方参考:https://docs.python.org/3/library/constants.html#Ellipsis 注意: ...

  9. UNIX系统高级编程——第五章-标准I/O库-总结

    基础: 标准I/O库在ANSI C中定义,可移植在不同的系统 文件指针(FILE):标准I/O库操作的不是文件描述符,而是流.FILE文件指针包含的是维护流所需的信息 通过函数fileno获取流的文件 ...

  10. 关于Subversion主从备份方式的调整(全量、增量脚本)更新

    本文引用于http://blog.chinaunix.net/uid-25266990-id-3369172.html 之前对Subversion服务器作了迁移,关于SVN的架构也走了调整,有单一的服 ...