2019.2.15 t2
考虑倒过来计算最短路径长度,设dis[u]表示在最坏情况下,点u到最近的一 个出口的最短路,则p个出口的dis值都是0,答案即为dis[0]。
- #include <cstdio>
- #include <iostream>
- #include <cstring>
- #include <cmath>
- #include <cctype>
- #include <queue>
- #include <algorithm>
- using namespace std;
- #define res register int
- #define LL long long
- #define inf 0x3f3f3f3f
- inline int read()
- {
- int x(),f(); char ch;
- while(!isdigit(ch=getchar())) if(ch=='-') f=-;
- while(isdigit(ch)) x=x*+ch-'',ch=getchar();
- return f*x;
- }
- inline int max(int x,int y){return x>y?x:y;}
- inline int min(int x,int y){return x<y?x:y;}
- const int N=+;
- int n,m,k,d,tot;
- int head[N],ver[N<<],nxt[N<<],edge[N<<];
- int dis[N],vis[N];
- inline void add(int x,int y,int z){
- ver[++tot]=y; nxt[tot]=head[x]; head[x]=tot; edge[tot]=z;
- }
- struct node{
- int id;
- LL dd;
- bool operator<(const node &n2) const {
- return dd>n2.dd;}
- };
- priority_queue<node> q;
- inline LL dij()
- {
- while(q.size())
- {
- node now=q.top(); q.pop();
- int x=now.id,z=now.dd;
- if(++vis[x]>d+) continue;
- if(vis[x]==d+ || !dis[x])
- {
- dis[x]=z;
- for(res i(head[x]) ; i ; i=nxt[i])
- {
- int y=ver[i];
- if(dis[y]==inf)
- q.push((node){ver[i],dis[x]+(LL)edge[i]});
- }
- }
- }
- }
- int main()
- {
- freopen("maze.in","r",stdin);
- freopen("maze.out","w",stdout);
- memset(dis,inf,sizeof(dis));
- n=read(); m=read(); k=read(); d=read();
- for(res i= ; i<=m ; i++)
- {
- int x=read(),y=read(),z=read();
- add(x,y,z); add(y,x,z);
- }
- for(res i= ; i<=k ; i++)
- {
- int x=read(); dis[x]=;
- q.push((node){x,});
- }
- dij();
- if(dis[]==inf) puts("-1");
- else cout<<dis[]<<endl;
- return ;
- }
2019.2.15 t2的更多相关文章
- Data truncation: Incorrect datetime value: 'May 15, 2019 4:15:37 PM
因为系统在windows下测试过是正常的 windows下的jdk+ windows下安装的mysql 全部cases通过 linux下的jdk + windows下安装的mysql 新增和更新,影响 ...
- MyBatis 配置/注解 SQL CRUD 经典解决方案(2019.08.15持续更新)
本文旨在记录使用各位大神的经典解决方案. 2019.08.14 更新 Mybatis saveOrUpdate SelectKey非主键的使用 MyBatis实现SaveOrUpdate mybati ...
- 【2019.8.15 慈溪模拟赛 T2】组合数(binom)(卢卡斯定理+高维前缀和)
卢卡斯定理 题目中说到\(p\)是质数. 而此时要求组合数向质数取模的结果,就可以用卢卡斯定理: \[C_x^y=C_{x\ div\ p}^{y\ div\ p}\cdot C_{x\ mod\ p ...
- 【2019.7.15 NOIP模拟赛 T2】与非树(nand)(树形DP)
树形\(DP\) 实际上,这道题应该不是很难. 我们设\(f_{x,i,j}\)表示在以\(x\)为根的子树内,原本应输出\(i\),结果输出了\(j\)的情况数. 转移时,为了方便,我们先考虑与,再 ...
- T2:中间值(median)———2019.10.15
代码: #include <bits/stdc++.h> int ri() { , f = ; ; ) + (x << ) - ' + c; return x * f; } ; ...
- 纪中OJ 2019.02.15【NOIP提高组】模拟 B 组 梦回三国 比赛题解(第一个)
声明 旁边的同学小 H(胡)对我说: “哟,比赛拿了 140,强!要知道,如果哥第三题 AC 了,哥就 230 了,你个废柴!!!(比赛实际分数 130 额呵)” 顿时,千万草泥马从我心中奔腾而过:你 ...
- 2019.03.15 ZJOI2019模拟赛 解题报告
得分: \(20+45+15=80\)(三题暴力全写挂...) \(T1\):Lyk Love painting 首先,不难想到二分答案然后\(DP\)验证. 设当前需验证的答案为\(x\),则一个暴 ...
- 第十八次CSP认证游记 | 2019.12.15
CSP认证的考试是Haogod介绍的,取得一定成绩之后能有机会参加CCSP的分赛区和全国决赛.这次来参加认证要感谢老师的奔走为我们申请学校的报销,虽然最终因为这不是比赛所以报名费和差旅费下不来,但是老 ...
- Python脱产8期 Day03 2019/4/15
一 变量的命名规范 1.只能由 字母, 数字, _, 组成. 2. 不能以数字开头 3.避免与系统关键字重名:重名不会报错,但系统的功能就被自定义的功能屏蔽掉了(严重不建议这样来做) 4.以_开头的 ...
随机推荐
- Node.js中流程控制
Node.js中的流程控制可以使用async,在使用之前需要先安装,使用npm安装 npm install async --g 下面主要介绍4种流程控制的方式: 1.串行无关联:async.serie ...
- CloudFoundry 快速上手笔记
1.登陆cf 2.登陆进入webservice 3.查看ruby版本 4.查看gem版本 5.安装CF 6.配置cf Download the CLI from github: https://git ...
- Python 中的 is 和 id-乾颐堂
(ob1 is ob2) 等价于 (id(ob1) == id(ob2)) 首先id函数可以获得对象的内存地址,如果两个对象的内存地址是一样的,那么这两个对象肯定是一个对象.和is是等价的.Pytho ...
- 基于mosquitto的MQTT服务器---SSL/TLS 单向认证+双向认证
基于mosquitto的MQTT服务器---SSL/TLS 单向认证+双向认证 摘自:https://blog.csdn.net/ty1121466568/article/details/811184 ...
- [SHELL]:let 命令详解
[SHELL]:let 命令详解 摘自:https://blog.csdn.net/happygongzhuo/article/details/6819099 let :简单的计算器 语 法let[ ...
- sed命令n,N,d,D,p,P,h,H,g,G,x解析2
摘自: https://blog.csdn.net/xiexingshishu/article/details/50514132 sed命令n,N,d,D,p,P,h,H,g,G,x解析 2016年0 ...
- [GO]使用select实现超时
package main import ( "fmt" "time" ) func main() { ch := make(chan int) quit := ...
- HDU 1104 Remainder (BFS求最小步数 打印路径)
题目链接 题意 : 给你N,K,M,N可以+,- ,*,% M,然后变为新的N,问你最少几次操作能使(原来的N+1)%K与(新的N)%k相等.并输出相应的操作. 思路 : 首先要注意题中给的%,是要将 ...
- 编写高质量代码改善C#程序的157个建议——建议113:声明变量前考虑最大值
建议113:声明变量前考虑最大值 假设正在开发一个工资系统,其中一个模块负责处理加薪.代码如下: static void Main(string[] args) { ; salary = (); Co ...
- [LeetCode 题解]: plusOne
前言 [LeetCode 题解]系列传送门: http://www.cnblogs.com/double-win/category/573499.html 1.题目描述 Given a no ...