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 分层的更多相关文章

  1. BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  M ...

  2. bzoj 2763: [JLOI2011]飞行路线【分层图+spfa】

    为什么早年的题总是从0开始标号啊--又zz了一次WA 分层图的题只有这一个套路吧,建分层图,然后优化时间是分层跑spfa然后层与层之间单独跑即可 #include<iostream> #i ...

  3. 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...

  4. Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1694  Solved: 635[Submit][Statu ...

  5. Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1728  Solved: 649[Submit][Statu ...

  6. bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...

  7. BZOJ 2763: [JLOI2011]飞行路线 最短路

    2763: [JLOI2011]飞行路线 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.lydsy.com/JudgeOnline/pr ...

  8. poj 2763: [JLOI2011]飞行路线(spfa分层图最短路)

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Submit: 2156 Solved: 818 [Submit][Statu ...

  9. bzoj 2763 [JLOI2011]飞行路线——分层图

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...

随机推荐

  1. className.class.getResourceAsStream与ClassLoader.getSystemResourceAsStream区别

    className.class.getResourceAsStream : 一: 要加载的文件和.class文件在同一目录下,例如:com.x.y 下有类Test.class ,同时有资源文件conf ...

  2. oracle to_date 函数

    update pamsodt0p10 set cursysdate =  to_date('2014-12-29 00:00:00','yyyy-mm-dd hh24:mi:ss') where cu ...

  3. Struts2,Spring,Hibernate优缺点

    struts框架具有组件的模块化,灵活性和重用性的优点,同时简化了基于MVC的web应用程序的开发. 优点: Struts跟Tomcat.Turbine等诸多Apache项目一样,是开源软件,这是它的 ...

  4. 修改flume源码,使其HTTPSource具备访问路径功能

    目前有一个需求,就是Flume可以作为一个类似于tomcat的服务器,可以通过post请求进行访问,并且路径需要:ip:port/contextPath格式. 经过一些资料获悉,httpSource只 ...

  5. JS(API-日期和math)

    JS(日期和math) 问题1.获取 2017-06-10 结果: 1.dt.getMonth() + 1 是真实的月份 2.month = '0' + month 中,month 是数字(numbe ...

  6. 完美支持Py3的微信开发库推荐

    之前分享了个代码,后来发现中文发送是乱码,应该是加密代码的问题,然后在又找到这个可完美使用的Py3微信库wechatpy:https://github.com/jxtech/wechatpy

  7. linux下面调试C、C++

    (1)写好makefile文件(支持debug) objects = Main.o Satellite.o TimeSystem.o  SRPPara:$(objects) g++ -g -o SRP ...

  8. java之Spring(AOP)前奏-动态代理设计模式(下)

    在上一章我们看到了,新增的三种类都能实现对原始功能类进行添加功能的事务处理,这三种类就是一个代理. 但是这种代理是写死的,怎样实现对任意接口添加自定义的代理呢? 我们先来看一下之前的代理实现: pub ...

  9. jquery touch 移动端上下滑动加载

    var touchStart, touchEnd, touchDiff = 80; $(window).on({ 'touchstart': function (e) { touchStart = e ...

  10. 重温《STL源码剖析》笔记 第五章

    源码之前,了无秘密  ——侯杰 序列式容器 关联式容器 array(build in) RB-tree vector set heap   map priority-queue multiset li ...