bzoj 2763 [JLOI2011]飞行路线 Dijikstra 分层
k<=10,所以每用一次机会就跳到一个新图中,
每一个图按原图建边,相邻两图中建边权为0的边
补一补dj,好像我以前觉得dj特别难,hhhhh
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<iostream>
#define N 500500
using namespace std;
int n,m,k,S,T;
struct point{
int st,dis;
bool operator < (const point &a)const{
return dis>a.dis;
}
}p[N];
int e=1,head[N],dis[N];
bool bo[N];
struct edge{
int u,v,w,next;
}ed[5000500];
void add(int u,int v,int w){
ed[e].u=u; ed[e].v=v; ed[e].w=w;
ed[e].next=head[u]; head[u]=e++;
}
priority_queue<point> q;
int dijkstra(){
memset(dis,0x7f,sizeof dis);
memset(bo,0,sizeof bo);
dis[S]=0;q.push((point){S,0});
while(!q.empty()){
point now=q.top();q.pop();
if(bo[now.st]) continue;
bo[now.st]=1;
for(int i=head[now.st];i;i=ed[i].next)
if(dis[now.st]+ed[i].w<dis[ed[i].v]){
dis[ed[i].v]=dis[now.st]+ed[i].w;
q.push((point){ed[i].v,dis[ed[i].v]});
}
}
int ans=0x7fffffff;
for(int i=0;i<=k;i++)
ans=min(ans,dis[i*n+T]);
return ans; }
int main(){
scanf("%d%d%d",&n,&m,&k);
scanf("%d%d",&S,&T);S++;T++;
int u,v,w;
for(int i=1;i<=m;i++){
scanf("%d%d%d",&u,&v,&w);
u++;v++;
for(int j=0;j<=k;j++){
add(j*n+u,j*n+v,w),add(j*n+v,j*n+u,w);
if(j<k)add(j*n+u,(j+1)*n+v,0),add(j*n+v,(j+1)*n+u,0);
}
}
int ans=dijkstra();
printf("%d\n",ans);
return 0;
}
bzoj 2763 [JLOI2011]飞行路线 Dijikstra 分层的更多相关文章
- BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec M ...
- bzoj 2763: [JLOI2011]飞行路线【分层图+spfa】
为什么早年的题总是从0开始标号啊--又zz了一次WA 分层图的题只有这一个套路吧,建分层图,然后优化时间是分层跑spfa然后层与层之间单独跑即可 #include<iostream> #i ...
- 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1694 Solved: 635[Submit][Statu ...
- Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1728 Solved: 649[Submit][Statu ...
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- BZOJ 2763: [JLOI2011]飞行路线 最短路
2763: [JLOI2011]飞行路线 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...
- poj 2763: [JLOI2011]飞行路线(spfa分层图最短路)
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2156 Solved: 818 [Submit][Statu ...
- bzoj 2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...
随机推荐
- node_acl 路径通配
最近做一个基于nodejs的权限管理,查阅了一两天,发现大致是这样的: passportjs node-oauth rbac node_acl express_acl connect-roles 需求 ...
- Day11 数据库的基本语法(偏重于查询)
数据库的介绍: 老师博客: MYSQL-1 - Yuan先生 - 博客园 http://www.cnblogs.com/yuanchenqi/articles/7269675.html 作业地址: h ...
- Linux 下常用的Shell 命令
英文原文链接:https://www.lopezferrando.com/30-interesting-shell-commands/ 1. 监控命令(每2秒运行一次) watch "ls ...
- vfd电子时钟制作
17年也没干个啥,年后就去折腾着玩意儿了,也不知道我折腾它还是它折腾我.反正总之现在勉强可以交作业了,呵呵 硬件: 1.罗耶振荡电路输出一路4v交流,一路25v交流 其中4v直接驱动灯丝,另一路经电桥 ...
- Python入门指南(超详细)
Python 是一门非常容易上手的语言,通过查阅资料和教程,也许一晚上就能写出一个简单的爬虫.但 Python 也是一门很难精通的语言,因为简洁的语法背后隐藏了许多黑科技.本文主要针对的读者是: 毫无 ...
- Sublime text 3 注册码激活码 版本号3143
—– BEGIN LICENSE —– TwitterInc 200 User License EA7E-890007 1D77F72E 390CDD93 4DCBA022 FAF60790 61AA ...
- Java c# 跨语言Json反序列化首字母大小写问题
C#标准是首字母大写,Java规范是首字母小写,在序列化成Json之后,反序列化会出现反序列化失败的问题.. 从C#反序列化成JavaBean的时候通过如下注解可以直接解决该问题 @JsonNamin ...
- 分布式消息队列XXL-MQ
<分布式消息队列XXL-MQ> 一.简介 1.1 概述 XXL-MQ是一款轻量级分布式消息队列,支持串行.并行和广播等多种消息模型.现已开放源代码,开箱即用. 支持三种消息模式: ...
- Golang 交叉编译 window/linux 文件
gox - 一款简单的交叉编译工具 下载地址:https://github.com/mitchellh/gox 使用 go get 命令安装: go get github.com/mitchellh/ ...
- JavaScript中的trim自定义
先直接贴代码 String.prototype.trimfy=function (val){ var demo=String(this); if(demo.indexOf(val)>=0){ i ...