BZOJ1579 [Usaco2009 Feb]Revamping Trails 道路升级
各种神作不解释QAQQQ
先是写了个作死的spfa本机过了交上去T了。。。
然后不想写Dijkstra各种自暴自弃。。。
最后改了一下步骤加了个SLF过了。。。
首先一个trivial的想法是$dis[p][t]$表示到了$p$号节点,用了$t$次变0技能,然后可以用$dis[q][t] + e[q][p]$和$dis[q][t - 1] + e[q][p] * 0$来更新
然后点数$O(n * k)$,边数$O(m * k)$,再加上usaco硬卡spfa。。。什么最终鬼畜。。。
其实我们可以这样子想:
先把用了$t$次技能的$dis$先算出来,这就是用$dis[q][t] + e[q][p]$更新
然后计算用了$t + 1$次技能,方法就是先用$dis[q]$更新$dis[p]$表示用了一次技能,再跑一边spfa就好了
/**************************************************************
Problem: 1579
User: rausen
Language: C++
Result: Accepted
Time:4312 ms
Memory:3872 kb
****************************************************************/ #include <cstdio>
#include <cstring>
#include <algorithm> using namespace std;
const int N = 1e4 + ;
const int M = 5e4 + ;
const int K = ;
const int inf = 1e9;
const int Maxlen = M * * ; struct edge {
int next, to, v;
edge(int _n = , int _t = , int _v = ) : next(_n), to(_t), v(_v) {}
} e[M << ]; int n, m, k;
int first[N], tot;
int dis[N], tmp[N], v[N]; char buf[Maxlen], *c = buf;
int Len; inline int read(); inline void Add_Edges(int x, int y, int z) {
e[++tot] = edge(first[x], y, z), first[x] = tot;
e[++tot] = edge(first[y], x, z), first[y] = tot;
} #define y e[x].to
void spfa(int S) {
static int i, x, q[], p;
static unsigned short l, r;
for (i = ; i <= n; ++i) dis[i] = i == S ? : inf;
q[l = r = ] = S, v[S] = ;
for (i = ; i <= k + ; ++i) {
while (l != r + ) {
p = q[l++];
for (x = first[p]; x; x = e[x].next)
if (dis[p] + e[x].v < dis[y]) {
dis[y] = dis[p] + e[x].v;
if (!v[y]) {
v[y] = ;
if (dis[y] < dis[q[l]]) q[--l] = y;
else q[++r] = y;
}
}
v[p] = ;
}
if (i == k + ) continue;
for (p = ; p <= n; ++p)
for (tmp[p] = inf, x = first[p]; x; x = e[x].next)
tmp[p] = min(tmp[p], dis[y]);
memcpy(dis, tmp, sizeof(dis));
for (p = ; p <= n; ++p)
if (!v[p]) {
v[p] = ;
if (dis[p] < dis[q[l]]) q[--l] = p;
else q[++r] = p;
}
}
}
#undef y int main() {
Len = fread(c, , Maxlen, stdin);
buf[Len] = '\0';
int i, x, y, z;
n = read(), m = read(), k = read();
for (i = ; i <= m; ++i) {
x = read(), y = read(), z = read();
Add_Edges(x, y, z);
}
spfa();
printf("%d\n", dis[n]);
return ;
} inline int read() {
int x = ;
while (*c < '' || '' < *c) ++c;
while ('' <= *c && *c <= '')
x = x * + *c - '', ++c;
return x;
}
BZOJ1579 [Usaco2009 Feb]Revamping Trails 道路升级的更多相关文章
- [BZOJ1579][Usaco2009 Feb]Revamping Trails 道路升级(二维最短路问题)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=1579 分析: 设d[i][j]表示从1走到i.改了j条边的最短路径长度 如果设i相连的 ...
- [BZOJ1579] [Usaco2009 Feb]Revamping Trails 道路升级(分层图最短路 + 堆优化dijk)
传送门 dis[i][j]表示第i个点,更新了j次的最短路 此题不良心,卡spfa #include <queue> #include <cstdio> #include &l ...
- 分层图最短路 【bzoj1579】[Usaco2009 Feb]Revamping Trails 道路升级
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Description 每天,农夫John需要经过一些道路去检查牛棚N里面的牛. 农场上有M(1<=M< ...
- Bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 dijkstra,堆,分层图
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1573 Solv ...
- BZOJ 1579: [Usaco2009 Feb]Revamping Trails 道路升级( 最短路 )
最短路...多加一维表示更新了多少条路 -------------------------------------------------------------------------------- ...
- 【BZOJ 1579】 1579: [Usaco2009 Feb]Revamping Trails 道路升级 (最短路)
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Description 每天,农夫John需要经过一些道路去检查牛棚N里面的牛. 农场上有M(1<=M< ...
- BZOJ_1579_[Usaco2009 Feb]Revamping Trails 道路升级_分层图最短路
BZOJ_1579_[Usaco2009 Feb]Revamping Trails 道路升级_分层图最短路 Description 每天,农夫John需要经过一些道路去检查牛棚N里面的牛. 农场上有M ...
- bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 -- 分层图最短路
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec Memory Limit: 64 MB Description 每天,农夫 ...
- bzoj 1579: [Usaco2009 Feb]Revamping Trails 道路升级 优先队列+dij
1579: [Usaco2009 Feb]Revamping Trails 道路升级 Time Limit: 10 Sec Memory Limit: 64 MBSubmit: 1768 Solv ...
随机推荐
- OpenCV installation on Linux
Getting the Cutting-edge OpenCV from the Git Repository Launch Git client and clone OpenCV repositor ...
- python_way day14 HTML
python_way day 14 HTML 一,标签 二.特殊字符 三,css <!DOCTYPE html> <html lang="en"> < ...
- STORM_0007_Multi-Lang protocol of Storm/多语言协议的翻译
原始地址: http://storm.apache.org/releases/1.0.1/Multilang-protocol.html 这个协议试用0.7.1之后的版本 通过ShellBolt和 ...
- hdu 4828 Grids 卡特兰数+逆元
Grids Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others) Problem D ...
- .htaccess文件 301重定向URL重写[NC][R][F][L]是什么意思
.htaccess中的[NC][R][F][L]几个标记是什么意思 NC: no case,就是说不区分大小写 R:redirect,重定向 F:forbidden,禁止访问 L:last,表示已经是 ...
- HLS播放权限测试记录
阿里云: http://live.mudu.tv/watch/11y1at.m3u8 斗鱼加密: http://hls3a.douyucdn.cn/live/485503r63zGiPn4D_550/ ...
- struts2 if标签示例
下面总结一下struts2 中if标签的使用 (1)判断字符串是否为空 <s:if test="user.username==null or user.username==''&quo ...
- Linux_常用命令_04_挂载
1. mount [-t vfstype] [-o options] device dir ZC: -o 后面跟多个option的话,用逗号隔开.(例如:"mount -o rw,remou ...
- Dolphin for Android(v11.5.1[Jetpack:内置])
1. 下载的地址为“http://www.techspot.com/downloads/5927-dolphin-browser-for-android.html” ZC: 由于 Google Pla ...
- 百度之星复赛Astar Round3
拍照 树状数组(SB了).求出静止状态下,每个点能看到多少个向右开的船c1[i],多少个向左开的船c2[i]. max{c1[i] + c2[j], (满足i <= j) }即为答案.从后往前 ...