bzoj5047 [Lydsy1709月赛]空间传送装置 最短路
题目传送门
https://lydsy.com/JudgeOnline/problem.php?id=5047
题解
题目中没有说可以停留在一个点等待。问了别人才知道停留是可以的。
那么既然停留是可以的,越先到达一个点肯定是越好的,所以一般的最短路算法依然是对的。
那么我们如果当前的这个点是 \(u\),要通过装置 \(w\) 在 \(dis[u]\) 时刻往后到达点 \(v\)。
可以发现,对于第 \(i\) 个装置,第 \(t\) 秒和第 \(t+c_ik\) 秒没有区别。所以一个装置所用时间只取决于 \(t \bmod c_i\)。同时,根据上面的结论,我们需要求出这个东西的后缀最大值。可以通过求出前 \(2c_i\) 个值中的后缀最大值来维护。
代码如下:
#include<bits/stdc++.h>
#define fec(i, x, y) (int i = head[x], y = g[i].to; i; i = g[i].ne, y = g[i].to)
#define dbg(...) fprintf(stderr, __VA_ARGS__)
#define File(x) freopen(#x".in", "r", stdin), freopen(#x".out", "w", stdout)
#define fi first
#define se second
#define pb push_back
template<typename A, typename B> inline char smax(A &a, const B &b) {return a < b ? a = b, 1 : 0;}
template<typename A, typename B> inline char smin(A &a, const B &b) {return b < a ? a = b, 1 : 0;}
typedef long long ll; typedef unsigned long long ull; typedef std::pair<int, int> pii;
template<typename I> inline void read(I &x) {
int f = 0, c;
while (!isdigit(c = getchar())) c == '-' ? f = 1 : 0;
x = c & 15;
while (isdigit(c = getchar())) x = (x << 1) + (x << 3) + (c & 15);
f ? x = -x : 0;
}
const int N = 100000 + 7;
const int M = 50 + 7;
const int S = 2000 + 7;
const int E = 200000 + 7;
const int INF = 0x3f3f3f3f;
int n, m, s, e;
int c[M], f[M][S << 1];
int dis[N], vis[N];
std::priority_queue<pii, std::vector<pii>, std::greater<pii> > q;
struct Edge { int to, ne, w; } g[E]; int head[N], tot;
inline void addedge(int x, int y, int z) { g[++tot].to = y, g[tot].w = z, g[tot].ne = head[x], head[x] = tot; }
inline void adde(int x, int y, int z) { addedge(x, y, z), addedge(y, x, z); }
inline void dijkstra() {
memset(dis, 0x3f, sizeof(dis));
dis[1] = s; q.push(pii(dis[1], 1));
while (!q.empty()) {
int x = q.top().se; q.pop();
if (vis[x]) continue;
vis[x] = 1;
for fec(i, x, y) if (smin(dis[y], dis[x] + f[g[i].w][dis[x] % c[g[i].w]])) q.push(pii(dis[y], y));
}
}
inline void work() {
dijkstra();
for (int i = 2; i <= n; ++i) printf("%d\n", dis[i] == INF ? -1 : dis[i] - s);
}
inline void init() {
read(n), read(m), read(s), read(e);
for (int i = 1; i <= m; ++i) {
int a, b, &c = ::c[i], d;
read(a), read(b), read(c), read(d);
f[i][c << 1] = INF;
for (int j = (c << 1) - 1; ~j; --j) f[i][j] = std::min((a * j + b) % c + d, f[i][j + 1] + 1);
}
int x, y, z;
for (int i = 1; i <= e; ++i) read(x), read(y), read(z), addedge(x, y, z);
}
int main() {
#ifdef hzhkk
freopen("hkk.in", "r", stdin);
#endif
init();
work();
fclose(stdin), fclose(stdout);
return 0;
}
bzoj5047 [Lydsy1709月赛]空间传送装置 最短路的更多相关文章
- 【BZOJ5047】空间传送装置 最短路
[BZOJ5047]空间传送装置 Description 太空中一共有n座星球,它们之间可以通过空间传送装置进行转移.空间传送装置分为m种,第i种装置可以用4个参数a_i,b_i,c_i,d_i来描述 ...
- bzoj5047: 空间传送装置
Description 太空中一共有n座星球,它们之间可以通过空间传送装置进行转移.空间传送装置分为m种,第i种装置可以用4个参 数a_i,b_i,c_i,d_i来描述.因为时空抖动的问题,在非整数时 ...
- 【bzoj5047】空间传送装置 堆优化Dijkstra
题目描述 n个点e条边的有向图,每条边是m种类型之一.第i种类型在第x时刻通过所花费的时间为$(a_i*x+b_i)\mod c_i+d_i$.可以在某个点停留.问:在s时刻从1号点出发,到达每个点所 ...
- 【BZOJ 5047 空间传送装置】
Time Limit: 20 Sec Memory Limit: 256 MBSubmit: 282 Solved: 121[Submit][Status][Discuss] Descriptio ...
- [Bzoj5043][Lydsy1709月赛]密码破译(按位dp)
5043: [Lydsy1709月赛]密码破译 Time Limit: 10 Sec Memory Limit: 256 MBSubmit: 477 Solved: 125[Submit][Sta ...
- BZOJ5047 空间传送装置 2017年9月月赛 最短路 SPFA
欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ5047 题意概括 概括??~别为难语文做一题错两题的我了…… 题解 我们发现,对于某一种装置,有c种 ...
- bzoj5049 [Lydsy1709月赛]导航系统 双向bfs
题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5049 题解 题面里面满眼的随机.既然数据完全随机,那就是在锻炼选手的乱搞能力啊. 根据一个常用 ...
- [BZOJ5109][LOJ #6252][P4061][CodePlus 2017 11月赛]大吉大利,今晚吃鸡!(最短路+拓扑排序+传递闭包+map+bitset(hash+压位))
5109: [CodePlus 2017]大吉大利,晚上吃鸡! Time Limit: 30 Sec Memory Limit: 1024 MBSubmit: 107 Solved: 57[Sub ...
- 【LibreOJ】#6354. 「CodePlus 2018 4 月赛」最短路 异或优化建图+Dijkstra
[题目]#6354. 「CodePlus 2018 4 月赛」最短路 [题意]给定n个点,m条带权有向边,任意两个点i和j还可以花费(i xor j)*C到达(C是给定的常数),求A到B的最短距离.\ ...
随机推荐
- 用soapUI开发webservice接口
1,下载soapUI软件,安装到本地 2,打开soapUI软件 3,创建一个开发好的接口 4,进行接口调用 测试:
- Favorite Donut
Favorite Donut Time Limit: 1500/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- ThreadPoolExecutor实现异步多线程
import time from concurrent.futures import ThreadPoolExecutor executor = ThreadPoolExecutor(max_work ...
- wangjunkai
<!Doctype html><html lang="en"> <head> <meta http-equiv="Content ...
- 126、TensorFlow Session的执行
# tf.Session.run 方法是一个执行tf.Operation或者计算tf.Tensor的一个主要的机制 # 你可以传递一个或者多个tf.Operation或者tf.Tensor对象来给tf ...
- Mybatis入门之MyBatis项目案例
一.项目案例演示 后台管理系统用户数据维护平台 所有用户数据查询 单个用户数据查询 用户数据修改(完善资料) 锁定用户账号 删除用户账号 彻底删除用户账号 二.数据库数据准备工作 数据库:mysql ...
- Dos.Common - 目录、介绍
引言: Dos.Common是一个开发中的常用类库,如HttpHelper.LogHelper.CacheHelper.CookieHelper.MapperHelper等等.与Dos.WeChat. ...
- mongo可视化工具adminMongo安装
git环境搭建下载地址:https://git-scm.com/downloads 此处,安装环境为windows操作系统,所以选择windows版本下载一直下一步,直至安装完成找到安装git的目录下 ...
- 【ABAP系列】SAP ABAP-模块 字符串操作基础知识
公众号:SAP Technical 本文作者:matinal 原文出处:http://www.cnblogs.com/SAPmatinal/ 原文链接:[ABAP系列]SAP ABAP-模块 字符串操 ...
- 手撸红黑树-Red-Black Tree 入门
一.学习红黑树前的准备: 熟悉基础数据结构 了解二叉树概念 二.红黑树的规则和规则分析: 根节点是黑色的 所有叶子节点(Null)是黑色的,一般会认定节点下空节点全部为黑色 如果节点为红色,那么子节点 ...