题意

给出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. Ubuntu16.04+OpenCV3.2.0+Opencv_Contrib3.2.0安装

    为了学习slam,在ubuntu16.04系统上安装opencv3.2.0以及对应的opencv_contrib3.2.0 安装过程 下载 Github上下载有的时候比较慢,我这里分享了OpenCV3 ...

  2. C#调用GPG命令进行加密解密文件操作

    public void GPG() { string password = "1234567890"; System.Diagnostics.ProcessStartInfo ps ...

  3. 获取xml字符串中的属性值

    pagexml = @"<?xml version='1.0' encoding='utf-8'?> <DATAPACKET Version='2.0'> <M ...

  4. 51nod 1267 4个数和为0 思路:哈希map+避免重复的点

    题目: 总结大佬们的思路: 思路1:所有数两两求和,存入map中,每次判断有没有相反数被标记过. 思路2:对所有数排序,排完所有数两两求和,结果正好是排好序的.然后扫一遍,二分查找看之前有没有相反数存 ...

  5. RabbitMQ笔记(3)

    消息从产生--->结束 1.生产者--->交换机--->队列--->消费者 2.生产者--->交换机--->队列 首先: 生产者:Exchange = n:1 Ex ...

  6. <ItemTemp>里写判断语句

    <%@ Language="C#" %> <html> <head></head> <body> <%=DateT ...

  7. LR编写post请求

    函数列表: web_submit_data(); web_custom_request(); web_get_int_property(); 1.web_submit_data(); 2.web_cu ...

  8. 1044 - Access denied for user 'root'@'%' to database 'xahy-blog' 解决方案二

    检查 user 表中'root'@'%' 的grant的权限 select HOST,USER,Grant_priv,Super_priv from mysql.`user`; 可以看到现在这两个权限 ...

  9. matlab Time-domain analysis 渐进式或者实时获取仿真值

    首先准备一个传递函数sys, 然后使用lsim(sys,u,t,x0)函数(通用的时序分析的函数) u: The input u is an array having as many rows as ...

  10. 从头认识java-17.2 线程中断(interrupt)

    这一章节我们来讨论一下线程中断(interrupt). 1.什么是线程中断(interrupt)? 就是在多线程执行的时候,我们给线程贴上一个中断的标记.可是不要求线程终止. 2.样例: 中断的样例: ...