题目传送门

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月赛]空间传送装置 最短路的更多相关文章

  1. 【BZOJ5047】空间传送装置 最短路

    [BZOJ5047]空间传送装置 Description 太空中一共有n座星球,它们之间可以通过空间传送装置进行转移.空间传送装置分为m种,第i种装置可以用4个参数a_i,b_i,c_i,d_i来描述 ...

  2. bzoj5047: 空间传送装置

    Description 太空中一共有n座星球,它们之间可以通过空间传送装置进行转移.空间传送装置分为m种,第i种装置可以用4个参 数a_i,b_i,c_i,d_i来描述.因为时空抖动的问题,在非整数时 ...

  3. 【bzoj5047】空间传送装置 堆优化Dijkstra

    题目描述 n个点e条边的有向图,每条边是m种类型之一.第i种类型在第x时刻通过所花费的时间为$(a_i*x+b_i)\mod c_i+d_i$.可以在某个点停留.问:在s时刻从1号点出发,到达每个点所 ...

  4. 【BZOJ 5047 空间传送装置】

    Time Limit: 20 Sec  Memory Limit: 256 MBSubmit: 282  Solved: 121[Submit][Status][Discuss] Descriptio ...

  5. [Bzoj5043][Lydsy1709月赛]密码破译(按位dp)

    5043: [Lydsy1709月赛]密码破译 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 477  Solved: 125[Submit][Sta ...

  6. BZOJ5047 空间传送装置 2017年9月月赛 最短路 SPFA

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ5047 题意概括 概括??~别为难语文做一题错两题的我了…… 题解 我们发现,对于某一种装置,有c种 ...

  7. bzoj5049 [Lydsy1709月赛]导航系统 双向bfs

    题目传送门 https://lydsy.com/JudgeOnline/problem.php?id=5049 题解 题面里面满眼的随机.既然数据完全随机,那就是在锻炼选手的乱搞能力啊. 根据一个常用 ...

  8. [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 ...

  9. 【LibreOJ】#6354. 「CodePlus 2018 4 月赛」最短路 异或优化建图+Dijkstra

    [题目]#6354. 「CodePlus 2018 4 月赛」最短路 [题意]给定n个点,m条带权有向边,任意两个点i和j还可以花费(i xor j)*C到达(C是给定的常数),求A到B的最短距离.\ ...

随机推荐

  1. [CF959F]Mahmoud and Ehab and yet another xor task题解

    搞n个线性基,然后每次在上一次的基础上插入读入的数,前缀和线性基,或者说珂持久化线性基. 然后一个num数组记录当时线性基里有多少数 然后每次前缀操作一下就珂以了 代码 #include <cs ...

  2. 【CF1257D】Yet Another Monster Killing Problem【贪心】

    题意:给定一些怪物,每天可以选一个勇士进去打怪,每个勇士每天只能打不超过si个怪物,每个勇士只能打能力值≤pi的怪物,问最少多少天打完所有怪物 题解:贪心,每天尽可能多的去打怪,那么存一个对于长度为i ...

  3. mysql 1067 - Invalid default value for 'addtime'错误处理

    错误描述 TABLE `bota_payment_closing` ( `id` int(11) NOT NULL AUTO_INCREMENT, `monthly` varchar(8) NOT N ...

  4. 20180826(05)- Java URL处理

    Java URL处理 URL(Uniform Resource Locator)中文名为统一资源定位符,有时也被俗称为网页地址.表示为互联网上的资源,如网页或者FTP地址. 本章节我们将介绍Java是 ...

  5. [CSP-S模拟测试]:传递(暴力+bitset)

    题目描述 我们称一个有向图$G$是传递的,当且仅当对于图$G$的三个不同顶点$a,b,c$,若图$G$中有一条边从$a$到$b$且有一条边从$b$到$c$,那么图中也有一条边从$a$到$c$.我们称一 ...

  6. sql server查询结果复制出来,没有换行(存进去的数据是换行的)

    https://stackoverflow.com/questions/53115490/how-to-correctly-insert-newline-in-nvarchar The problem ...

  7. wget下载简单语法

    文章参考:https://linuxtools-rst.readthedocs.io/zh_CN/latest/tool/wget.html nasa wget 下载: https://disc.gs ...

  8. npm install 安装过程卡住不动

    修改 npm 的安装目录下的 npmrc文件 增加一条 registry=http://registry.cnpmjs.org $ npm config set registry http://reg ...

  9. Linux-磁盘配额

    磁盘配额作用是限制普通用户使用的磁盘空间和创建文件的个数,不至于因为个别人的浪费而影响所有人的使用,需要内核的支持 注意:目前只有 ext2 ext3文件系统支持 需要用户程序quota程序包 先查看 ...

  10. mariadb(一)基础

    一.数据库介绍 1.什么是数据库? 简单的说,数据库就是一个存放数据的仓库,这个仓库是按照一定的数据结构(数据结构是指数据的组织形式或数据之间的联系)来组织,存储的,我们可以通过数据库提供的多种方法来 ...