「BJWC2012」冻结
传送门
Luogu
解题思路
分层图最短路,层与层之间的边的边权减半,然后就是板子了。
细节注意事项
- 咕咕咕。
参考代码
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#define rg register
using namespace std;
template < class T > inline void read(T& s) {
s = 0; int f = 0; char c = getchar();
while (!isdigit(c)) f |= c == '-', c = getchar();
while (isdigit(c)) s = s * 10 + c - 48, c = getchar();
s = f ? -s : s;
}
const int _ = 52 * 52;
const int __ = 1002 + 52 * 2002;
int tot, head[_], nxt[__ << 1], ver[__ << 1], w[__ << 1];
inline void Add_edge(int u, int v, int d)
{ nxt[++tot] = head[u], head[u] = tot, ver[tot] = v, w[tot] = d; }
int n, m, k, vis[_], dis[_];
inline int id(int u, int x) { return u + x * n; }
inline void Dijkstra() {
static priority_queue < pair < int, int > > Q;
memset(dis + 1, 0x3f, sizeof (int) * (n * (k + 1)));
dis[1] = 0, Q.push(make_pair(0, 1));
while (!Q.empty()) {
int u = Q.top().second; Q.pop();
if (vis[u]) continue; vis[u] = 1;
for (rg int i = head[u]; i; i = nxt[i]) {
int v = ver[i];
if (dis[v] > dis[u] + w[i])
dis[v] = dis[u] + w[i], Q.push(make_pair(-dis[v], v));
}
}
}
int main() {
#ifndef ONLINE_JUDGE
freopen("cpp.in", "r", stdin);
freopen("cpp.out", "w", stdout);
#endif
read(n), read(m), read(k);
for (rg int u, v, d; m--; ) {
read(u), read(v), read(d);
Add_edge(u, v, d), Add_edge(v, u, d);
for (rg int i = 1; i <= k; ++i) {
Add_edge(id(u, i), id(v, i), d);
Add_edge(id(v, i), id(u, i), d);
Add_edge(id(u, i - 1), id(v, i), d >> 1);
Add_edge(id(v, i - 1), id(u, i), d >> 1);
}
}
Dijkstra();
int ans = 2147483647;
for (rg int i = 0; i <= k; ++i)
ans = min(ans, dis[id(n, i)]);
printf("%d\n", ans);
return 0;
}
完结撒花 \(qwq\)
「BJWC2012」冻结的更多相关文章
- 「译」JUnit 5 系列:条件测试
原文地址:http://blog.codefx.org/libraries/junit-5-conditions/ 原文日期:08, May, 2016 译文首发:Linesh 的博客:「译」JUni ...
- 「译」JUnit 5 系列:扩展模型(Extension Model)
原文地址:http://blog.codefx.org/design/architecture/junit-5-extension-model/ 原文日期:11, Apr, 2016 译文首发:Lin ...
- JavaScript OOP 之「创建对象」
工厂模式 工厂模式是软件工程领域一种广为人知的设计模式,这种模式抽象了创建具体对象的过程.工厂模式虽然解决了创建多个相似对象的问题,但却没有解决对象识别的问题. function createPers ...
- 「C++」理解智能指针
维基百科上面对于「智能指针」是这样描述的: 智能指针(英语:Smart pointer)是一种抽象的数据类型.在程序设计中,它通常是经由类型模板(class template)来实做,借由模板(tem ...
- 「JavaScript」四种跨域方式详解
超详细并且带 Demo 的 JavaScript 跨域指南来了! 本文基于你了解 JavaScript 的同源策略,并且了解使用跨域跨域的理由. 1. JSONP 首先要介绍的跨域方法必然是 JSON ...
- 「2014-5-31」Z-Stack - Modification of Zigbee Device Object for better network access management
写一份赏心悦目的工程文档,是很困难的事情.若想写得完善,不仅得用对工具(use the right tools),注重文笔,还得投入大把时间,真心是一件难度颇高的事情.但,若是真写好了,也是善莫大焉: ...
- 「2014-3-18」multi-pattern string match using aho-corasick
我是擅(倾)长(向)把一篇文章写成杂文的.毕竟,写博客记录生活点滴,比不得发 paper,要求字斟句酌八股结构到位:风格偏杂文一点,也是没人拒稿的.这么说来,arxiv 就好比是 paper 世界的博 ...
- 「2014-3-17」C pointer again …
记录一个比较基础的东东-- C 语言的指针,一直让人又爱又恨,爱它的人觉得它既灵活又强大,恨它的人觉得它太过于灵活太过于强大以至于容易将人绕晕.最早接触 C 语言,还是在刚进入大学的时候,算起来有好些 ...
- 「2014-3-13」Javascript Engine, Java VM, Python interpreter, PyPy – a glance
提要: url anchor (ajax) => javascript engine (1~4 articles) => java VM vs. python interpreter =& ...
随机推荐
- 使用Vue时localhost:8080中localhost换成ip地址后无法显示页面的问题
解决办法是:在package.json中 然后重新启动服务器 npm run dev 就正常显示了.
- 语义化标签&唯一性标签
语义化标签 em\i表示倾斜,b\strong表示加粗,但其中只有strong和em具有着重的语义 img:alt属性当图片无法显示,显示alt的文字,根本需求是为了SEO,是必须属性,alt属性长度 ...
- 影响IPSec的网络问题
影响IPSec VPN的网络问题:①.动态地址问题:两个 站点之间IPSec VPN的条件是站点之间有固定的IP地址,假如说分支站点采用ADSL上网链路,那么其IP地址是动态的,那么就在VPN时出现问 ...
- 配置SVTI
路由器SVTI站点到站点VPN 在IOS 12.4之前建立安全的站点间隧道只能采用GRE over IPSec,从IOS 12.4之后设计了一种全新的隧道技术,即VIT(Virtual ...
- 策略模式,重构if-else
最近完成了我们公司的公众号开发,在微信消息路由选择的时候一开始都是用if-else 来判断,后面if-else月写越多显得十分的乱.在网上简单查了一下解决方法,果然有不少干货,感觉最经典最简洁的还是使 ...
- 温湿度传感器AM2302(DH22)
AM2302 3.3V - 5.5V,建议供电电压为 5V单总线通信模式时,SDA 上拉(开漏)后与微处理器的 I/O 端口相连.单总线通信特殊说明: 0.功耗待机40~50uA;测量1~1.5m ...
- mcast_join_source_group函数
#include <errno.h> #include <net/if.h> #include <sys/socket.h> #define SA struct s ...
- centos 安装phpize
yum -y install php-devel 然后 /usr/bin/phpize
- centos7.4安装gitlab
1. 安装依赖软件 yum -y install policycoreutils openssh-server openssh-clients postfix 2.下载gitlab安装包,然后安装 c ...
- Java基础知识笔记第八章:常用的实体类
String类 String类位于lang包下 java会默认导入lang包下的类,所以可以直接使用,注意String是final类所以不能有子类 构造String对象: 常量对象:String常量也 ...