题意

给出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. mount ntfs 失败解决办法

    在双系统中,ntfs可能会应为windows的缓存而挂载失败.可用下面命令修复. Use ntfsfix in the terminal, even if you can't access Windo ...

  2. localStorage、sessionStorage的区别

    1.localStorage生命周期是永久的, sessionStorage生命周期为当前窗口或标签页,一旦窗口或标签页被永久关闭了,那么所有通过sessionStorage存储的数据也就被清空了. ...

  3. HD-ACM算法专攻系列(12)——Integer Inquiry

    问题描述: 源码: import java.math.BigInteger; import java.util.*; public class Main { //主函数 public static v ...

  4. HDU 1505 City Game【DP】

    题意:是二维的1506,即在1506的基础上,再加一个for循环,即从第一行到最后一行再扫一遍--- 自己写的时候,输入的方法不对---发现输不出结果,后来看了别人的----@_@发现是将字母和空格当 ...

  5. Dispatch Groups

    Dispatch Groups are objects that allow several tasks to be grouped for later joining. Tasks can be a ...

  6. 死锁,线程协作(同步,阻塞队列,Condition,管道流)

    synchronized死锁 package com.thread.demo.deadlock; public class DeadLock { private static Object lock1 ...

  7. java的selenium环境搭建

    1.下载jdk1.8   环境变量我的博客有我就不说                   selenium下载地址:http://npm.taobao.org/mirrors/selenium 2.下 ...

  8. 模块-- HASH

    模块 HASH   一 MD5 import hashlib h = hashlib.md5() # In [237]: h # Out[237]: <md5 HASH object @ 0x0 ...

  9. vue之父子组件间通信实例讲解(props、$ref、$emit)

       组件间如何通信,也就成为了vue中重点知识了.这篇文章将会通过props.$ref和 $emit 这几个知识点,来讲解如何实现父子组件间通信. 组件是 vue.js 最强大的功能之一,而组件实例 ...

  10. 移动端mete设置

    <!DOCTYPE html> <!-- 使用 HTML5 doctype,不区分大小写 --> <html lang="zh-cmn-Hans"&g ...