P1462 通往奥格瑞玛的道路【二分+Dij】
P1462 通往奥格瑞玛的道路
推荐题目
题目背景
在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量
有一天他醒来后发现自己居然到了联盟的主城暴风城
在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛
题目描述
在艾泽拉斯,有n个城市。编号为1,2,3,...,n。
城市之间有m条双向的公路,连接着两个城市,从某个城市到另一个城市,会遭到联盟的攻击,进而损失一定的血量。
每次经过一个城市,都会被收取一定的过路费(包括起点和终点)。路上并没有收费站。
假设1为暴风城,n为奥格瑞玛,而他的血量最多为b,出发时他的血量是满的。
歪嘴哦不希望花很多钱,他想知道,在可以到达奥格瑞玛的情况下,他所经过的所有城市中最多的一次收取的费用的最小值是多少。
输入格式
第一行3个正整数,n,m,b。分别表示有n个城市,m条公路,歪嘴哦的血量为b。
接下来有n行,每行1个正整数,fi。表示经过城市i,需要交费fi元。
再接下来有m行,每行3个正整数,ai,bi,ci(1<=ai,bi<=n)。表示城市ai和城市bi之间有一条公路,如果从城市ai到城市bi,或者从城市bi到城市ai,会损失ci的血量。
输出格式
仅一个整数,表示歪嘴哦交费最多的一次的最小值。
如果他无法到达奥格瑞玛,输出AFK。
输入输出样例
- 4 4 8
- 8
- 5
- 6
- 10
- 2 1 2
- 2 4 1
- 1 3 4
- 3 4 3
- 10
说明/提示
对于60%的数据,满足n≤200,m≤10000,b≤200
对于100%的数据,满足n≤10000,m≤50000,b≤1000000000
对于100%的数据,满足ci≤1000000000,fi≤1000000000,可能有两条边连接着相同的城市。
题意:找到一条从 1 到 n 的路,且满足路上在某个点交过路费的最大值要最小。
- #include <bits/stdc++.h>
- #define dbg(x) cout << #x << "=" << x << endl
- #define eps 1e-8
- #define pi acos(-1.0)
- using namespace std;
- typedef long long LL;
- template<class T>inline void read(T &res)
- {
- char c;T flag=;
- while((c=getchar())<''||c>'')if(c=='-')flag=-;res=c-'';
- while((c=getchar())>=''&&c<='')res=res*+c-'';res*=flag;
- }
- namespace _buff {
- const size_t BUFF = << ;
- char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
- char getc() {
- if (ib == ie) {
- ib = ibuf;
- ie = ibuf + fread(ibuf, , BUFF, stdin);
- }
- return ib == ie ? - : *ib++;
- }
- }
- int qread() {
- using namespace _buff;
- int ret = ;
- bool pos = true;
- char c = getc();
- for (; (c < '' || c > '') && c != '-'; c = getc()) {
- assert(~c);
- }
- if (c == '-') {
- pos = false;
- c = getc();
- }
- for (; c >= '' && c <= ''; c = getc()) {
- ret = (ret << ) + (ret << ) + (c ^ );
- }
- return pos ? ret : -ret;
- }
- const int maxn = 1e5 + ;
- const int inf = 0x3f3f3f3f;
- int head[maxn << ], edge[maxn << ], w[maxn << ], nxt[maxn << ];
- int cnt, b;
- int f[maxn << ];
- inline void BuildGraph (int u, int v, int c) {
- cnt++;
- edge[cnt] = v;
- nxt[cnt] = head[u];
- w[cnt] = c;
- head[u] = cnt;
- }
- struct node {
- int u,v;
- bool operator <(const node &t) const {
- return u > t.u;
- }
- };
- int n,m,s,t,maxx;
- int dis[maxn];
- priority_queue < node > q;
- bool check(int x) {
- if(x < f[])
- return ;
- for (int i = ; i <= n; ++i) {
- dis[i] = inf;
- }
- dis[] = ;
- node temp;
- temp.u = ;
- temp.v = ;
- q.push(temp);
- while(!q.empty()) {
- int u = q.top().v;
- int d = q.top().u;
- q.pop();
- if(d != dis[u]) continue;
- for (int i = head[u]; i; i = nxt[i]) {
- int v = edge[i];
- int c = w[i];
- if(dis[v] > dis[u] + c && f[v] <= x) {
- dis[v] = dis[u] + c;
- node p;
- p.u = dis[v], p.v = v;
- q.push(p);
- }
- }
- }
- if(dis[n] < b) {
- return ;
- }
- return ;
- }
- int main()
- {
- scanf("%d %d %d",&n,&m,&b);
- for (int i = ; i <= n; ++i) {
- scanf("%d",&f[i]);
- maxx = max(maxx, f[i]);
- }
- for (int i = ; i <= m; i++) {
- int u, v, c;
- scanf("%d %d %d",&u,&v,&c);
- BuildGraph(u, v, c);
- BuildGraph(v, u, c);
- }
- if(!check(inf)) {
- puts("AFK");
- return ;
- }
- int l = , r = inf, mid = (l + r) >> ;
- while(l <= r) {
- if(check(mid)) {
- r = mid - ;
- mid = (l + r) >> ;
- }
- else {
- l = mid + ;
- mid = (l + r) >> ;
- }
- }
- printf("%d\n",l);
- return ;
- }
P1462 通往奥格瑞玛的道路【二分+Dij】的更多相关文章
- P1462 通往奥格瑞玛的道路 (二分+最短路)
题目 P1462 通往奥格瑞玛的道路 给定\(n\)个点\(m\)条边,每个点上都有点权\(f[i]\),每条边上有边权,找一条道路,使边权和小于给定的数\(b\),并使最大点权最小. 解析 二分一下 ...
- [Luogu P1462] 通往奥格瑞玛的道路 (二分答案+最短路径)
题面 传送门:https://www.luogu.org/problemnew/show/P1462 Solution 这道题如果去除掉经过城市的收费.那么就是裸的最短路 但是题目要求经过城市中最多的 ...
- 洛谷 - P1462 - 通往奥格瑞玛的道路 - 二分 - Dijkstra
https://www.luogu.org/problem/P1462 感觉,要二分最大收费权的城市,把小于等于它的全部插进去,Dijkstra一下求出最小的血量.这样感觉太暴力了. 考虑只有1000 ...
- 洛谷P1462 通往奥格瑞玛的道路[二分答案 spfa 离散化]
题目背景 在艾泽拉斯大陆上有一位名叫歪嘴哦的神奇术士,他是部落的中坚力量 有一天他醒来后发现自己居然到了联盟的主城暴风城 在被众多联盟的士兵攻击后,他决定逃回自己的家乡奥格瑞玛 题目描述 在艾泽拉斯, ...
- 洛谷P1462通往奥格瑞玛的道路——二分答案最短路
题目:https://www.luogu.org/problemnew/show/P1462 最大值最小问题,二分答案. 代码如下: #include<iostream> #include ...
- 洛谷 P1462 通往奥格瑞玛的道路——二分+spfa
上一波链接 https://www.luogu.org/problem/P1462 这道题我们考虑二分答案 然后每次跑一次spfa判断是否能够到达n点 tips:在不考虑负权边的前提下我们写最短路最好 ...
- Luogu P1462 通往奥格瑞玛的道路 二分答案+最短路
先二分答案,再跑最短路,跑的时候遇到 过路费超过二分的答案的 就不拿他更新最短路 #include<cstdio> #include<iostream> #include< ...
- 洛谷 P1462 通往奥格瑞玛的道路 二分 最短路
#include<cstdio> #include<queue> #include<cstring> #include<algorithm> using ...
- 洛谷P1462 通往奥格瑞玛的道路(二分+spfa,二分+Dijkstra)
洛谷P1462 通往奥格瑞玛的道路 二分费用. 用血量花费建图,用单源最短路判断 \(1\) 到 \(n\) 的最短路花费是否小于 \(b\) .二分时需要不断记录合法的 \(mid\) 值. 这里建 ...
随机推荐
- 使用Java实现三个线程交替打印0-74
使用Java实现三个线程交替打印0-74 题目分析 三个线程交替打印,即3个线程是按顺序执行的.一个线程执行完之后,唤醒下一个线程,然后阻塞,等待被该线程的上一个线程唤醒.执行的顺序是一个环装的队列 ...
- Thread Based Parallelism - Thread Synchronization With a Condition
Thread Based Parallelism - Thread Synchronization With a Condition from threading import Thread, Con ...
- malloc返回地址的对齐问题
http://man7.org/linux/man-pages/man3/malloc.3.html RETURN VALUE top The malloc() and calloc( ...
- [CSS]三大特性之一继承性、层叠性、优先级
<style> div { color: red; font-size: 30px; {#background: #0066ff;#} } </style> <!-- 1 ...
- WebSocket协议分析
WebSocket协议分析 1.什么是WebSocket协议 WebScoket协议是基于TCP协议建立的全双工通信,所谓的全双工通信就是双向同时通信. 2.WebSocket协议优点 WebSock ...
- windows下修改tomcat的startup.bat脚本文件后台运行
1.修改startup.bat文件 rem Get remaining unshifted command line arguments and save them in the set CMD_LI ...
- mitmproxy--Cannot establish TLS with client (sni: e.crashlytics.com): TlsException("(-1, 'Unexpected EOF')",) 解决办法
按崔哥(https://cuiqingcai.com/5391.html)的安装步骤一步步下来,会报这个错误: Cannot establish TLS with client (sni: e.cra ...
- 带输入提示的搜索框ajax请求
先放图 首先要引用的文件有: base.css https://www.cnblogs.com/chenyingying0/p/12363689.html jquery.js transition. ...
- Android中使用getDrawable时提示:Call requires API level 21(current min is 15)
场景 在通过getDrawable方法获取照片资源时提示: Call requires API level 21(current min is 15) 注: 博客: https://blog.csdn ...
- LeetCode 57. Insert Interval 插入区间 (C++/Java)
题目: Given a set of non-overlapping intervals, insert a new interval into the intervals (merge if nec ...