【luogu P1462 通往奥格瑞玛的道路】 题解
题目链接:https://www.luogu.org/problemnew/show/P1462
记住HP=0也叫死。
#include <queue>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn = 5000001;
const int inf = 0x7f;
long long n, m, s, dis[maxn], hp, f[maxn], u[maxn];
bool vis[maxn<<2];
struct edge{
int to, from, len, next;
}e[maxn];
int head[maxn], cnt;
void add(int u, int v, int w)
{
e[++cnt].from = u;
e[cnt].len = w;
e[cnt].to = v;
e[cnt].next = head[u];
head[u] = cnt;
}
int SPFA(int top)
{
memset(dis,inf,sizeof(dis));
memset(vis,0,sizeof(vis));
queue<int> q;
vis[1] = 1;
dis[1] = 0;
q.push(1);
while(!q.empty())
{
int now = q.front(); q.pop();
vis[now] = 0;
for(int i = head[now]; i != -1; i = e[i].next)
{
if(dis[e[i].to] > dis[now]+e[i].len && f[e[i].to]<=top)
{
dis[e[i].to] = dis[now]+e[i].len;
if(vis[e[i].to] == 0)
{
vis[e[i].to] = 1;
q.push(e[i].to);
}
}
}
}
if(dis[n] < hp)
return true;
else
return false;
}
int main()
{
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
memset(head,-1,sizeof(head));
scanf("%d%d%d",&n,&m,&hp);
for(int i = 1; i <= n; i++)
{
scanf("%d",&f[i]);
u[i] = f[i];
}
for(int i = 1; i <= m; i++)
{
int u, v, w;
scanf("%d%d%d",&u,&v,&w);
add(u,v,w);
add(v,u,w);
}
if(SPFA(0x7fffffff) == false)
{
printf("AFK\n");
return 0;
}
sort(u+1,u+1+n);
int l = 1, r = n, mid, ans = 0;
while(l <= r)
{
mid = (l+r)/2;
if(SPFA(u[mid]) == true)
{
ans = u[mid];
r = mid-1;
}
else
l = mid+1;
}
printf("%d\n",ans);
return 0;
}
【luogu P1462 通往奥格瑞玛的道路】 题解的更多相关文章
- luogu P1462 通往奥格瑞玛的道路--spfa+二分答案
P1462 通往奥格瑞玛的道路 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡 ...
- [Luogu P1462] 通往奥格瑞玛的道路 (二分答案+最短路径)
题面 传送门:https://www.luogu.org/problemnew/show/P1462 Solution 这道题如果去除掉经过城市的收费.那么就是裸的最短路 但是题目要求经过城市中最多的 ...
- 洛谷 P1462 通往奥格瑞玛的道路 题解
P1462 通往奥格瑞玛的道路 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡 ...
- Luogu P1462 通往奥格瑞玛的道路(最短路+二分)
P1462 通往奥格瑞玛的道路 题面 题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己 ...
- 洛谷P1462通往奥格瑞玛的道路题解
[题目]: https://www.luogu.org/problemnew/show/P1462 题意 题目是给定了一张双向边,有边权的图,然后让我们求出一个最小值,满足一条路径上的最大的费用小于这 ...
- Luogu P1462 通往奥格瑞玛的道路【二分/最短路】
题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...
- 洛谷P1462 通往奥格瑞玛的道路 题解 最短路+二分答案
题目链接:https://www.luogu.com.cn/problem/P1462 题目大意: 有 \(n\) 个点 \(m\) 条边,每个点有一个点权,每个边有一个边权.求所有长度不超过 \(b ...
- luogu P1462 通往奥格瑞玛的道路
嘟嘟嘟 这道题的题面相当的迷,我看了半天都没懂.最后看了题解的解释才懂. 他是这么个意思:对于所有能活着走到终点的路径,输出每一条路径中过路费最多的城市的最小值. 那么自然想到二分过路费,然后用dij ...
- Luogu P1462 通往奥格瑞玛的道路 二分答案+最短路
先二分答案,再跑最短路,跑的时候遇到 过路费超过二分的答案的 就不拿他更新最短路 #include<cstdio> #include<iostream> #include< ...
随机推荐
- CentOS初试
由于实在是对ubuntu不太感冒,加上买的鸟哥又是拿CentOS做的例子,所以我就把ubuntu换成了CentOS6.5.依旧win7,CentOS 双系统,具体过程参照http://www.cnbl ...
- TOJ 3744 Transportation Costs
描述 Minya Konka decided to go to Fuzhou to participate in the ACM regional contest at their own expen ...
- unity 热更新方案ILRuntime
https://github.com/meta-42/ILRuntime 教程 https://ourpalm.github.io/ILRuntime/public/v1/guide/index.ht ...
- 九度oj题目1385:重建二叉树
题目1385:重建二叉树 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4419 解决:1311 题目描述: 输入某二叉树的前序遍历和中序遍历的结果,请重建出该二叉树.假设输入的前序遍历和 ...
- 【Elasticsearch】集群管理
8.1 Elasticsearch时光机 Elasticsearch的快照,防止出错,灾备8.1.1 创建快照存储库创建快照之前必须建一个存储库,有如下几个方面,name,type,settings, ...
- 从零开始写C# MVC框架之--- 项目结构
框架总分2个项目:Web开发项目.帮助类项目 (ZyCommon.Zy.Utilities) 1.ZyCommon,是Web开发项目结构.新建一个空解决方案,再建Data.Service.ZyWeb解 ...
- 在 Linux 上创建第一个 Service Fabric Java 应用程序
先决条件 开始之前,请安装 Service Fabric SDK.Azure CLI,并在 Linux 开发环境中设置开发群集. 如果使用 Mac OS X,则可使用 Vagrant 在虚拟机中设置 ...
- 2017年10月22日 基础SQL语句&数据库创建主外键关系
1.SQL语句的注释 双减号:-- 或者/**/2.创建数据库create database 数据库名称(不允许以数字开头,不允许以符号开头,不要起汉语名字) 3.如何选中这个数据库use 数据库名 ...
- HDU 4268 multiset
http://acm.hust.edu.cn/vjudge/contest/123100#problem/B #include <iostream> #include <string ...
- 编写可维护的 Gruntfile.js
load-grunt-tasks 插件 首先介绍下 load-grunt-tasks 这个插件. 我们一般都会把所有用到的插件以及插件的配置写到 Gruntfile.js 里面,对于小项目来说这个文件 ...