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 ...
随机推荐
- Android tablayout增加选择tab 的事件.
tablayout在点击或者滑动的时候会触发监听事件 , 当你调用这个方法的时候 会触发事件 mTablayout.addOnTabSelectedListener(new TabLayout.On ...
- (转载)15 个 Android 通用流行框架大全
15 个 Android 通用流行框架大全 时间:2017-03-20 11:36来源:未知 作者:admin 点击: 2089 次 15 个 Android 通用流行框架大全 1. 缓存 Dis ...
- (Spring+IBatis+Struts1+Struts2+Hibernate+Java EE+Oracle)
原文出处:http://space.itpub.net/6517/viewspace-609654 1.Spring架构图 Spring是一个开源框架,是为了解决企业应用程序开发复杂性而创建的.框架的 ...
- layui中选中select标签 隐藏div
在select标签中添加 lay-filter="cartype" <script type="text/javascript"> form.on( ...
- Shiro结合Spring boot开发权限管理系统
前一篇文章说了,我从开始工作就想有一个属于自己的博客系统,当然了,我想的是多用户的博客,大家都可以发文章记笔记,我最初的想法就是这样. 博客系统搭建需要使用的技术: 1.基于Spring boot 2 ...
- hdu5321 beautiful set(莫比乌斯反演)
设\(cnt[i]\)为权值为i的倍数的数的数量. \(f0[i],f1[i]\)分别为两种方法\(gcd=i\)的贡献是i的多少倍. \(F0[i],F1[i]\)分别为两种方法\(gcd\)为\( ...
- [洛谷P2183]巧克力
题目大意:有n块巧克力,每块巧克力有一个大小.巧克力可以切成若干份.现在要你切成大小相等的m块,且尽可能大.求这个大小. 解题思路:我们二分巧克力切成的大小,然后计算能切成多少块,判断即可.由于最大的 ...
- linux 安装常用库
在CentOS安装软件的时候,可能缺少一部分支持库,而报错.这里首先安装系统常用的支持库.那么在安装的时候就会减少很多的错误的出现. [root@bogon 桌面]# yum install -y ...
- Linux用户与用户组
Linux用户与用户组 Linux系统是一个多用户多任务的分时操作系统,任何一个要使用系统资源的用户,都必须首先向系统管理员申请一个账号,然后以这个账号的身份进入系统. 用户的账号一方面可以帮助系统管 ...
- 洛谷 P2665 [USACO08FEB]连线游戏Game of Lines
P2665 [USACO08FEB]连线游戏Game of Lines 题目背景 Farmer John最近发明了一个游戏,来考验自命不凡的贝茜. 题目描述 Farmer John has chall ...