题目链接


Solution

建立 \(k+1\) 层图跑 \(Dijkstra\) 就好了.

Code

#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=200008;
int n,m,k,s,t;
struct sj{
int to;
int next;
int w;
}a[maxn*10];
int head[maxn],size;
ll dis[maxn],dist[maxn]; void add(int x,int y,int w)
{
a[++size].to=y;
a[size].next=head[x];
head[x]=size;
a[size].w=w;
} int read()
{
char ch=getchar(); int f=1,w=0;
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch<='9'&&ch>='0'){w=w*10+ch-'0';ch=getchar();}
return f*w;
} struct node {
int u;ll d;
bool operator <(const node& rhs) const {
return d>rhs.d;
}
}; inline void Dijkstra()
{
memset(dis,127,sizeof(dis));
dis[s]=0;
priority_queue<node> q;
q.push((node){s,0});
while(!q.empty())
{
node xx=q.top(); q.pop();
int u=xx.u,d=xx.d;
if(d!=dis[u])continue;
for(int i=head[u];i;i=a[i].next)
{
int tt=a[i].to,w=a[i].w;
if(dis[u]+w<dis[tt])
{
dis[tt]=dis[u]+w;
q.push((node){tt,dis[tt]});
}
}
}
} void pre(int x,int y,int w)
{
for(int i=0;i<=k;i++)
add(x+n*i,y+n*i,w),
add(y+n*i,x+n*i,w);
for(int i=0;i<k;i++)
add(x+n*i,y+n*i+n,0),
add(y+n*i,x+n*i+n,0);
} int main()
{
n=read(); m=read(); k=read();
s=read(); t=read();
for(int i=1;i<=m;i++)
{
int x,y,w;
x=read();
y=read();
w=read();
pre(x,y,w);
}
for(int i=0;i<=k;i++)
add(t+i*n,n*(k+1)+1,0);
Dijkstra();
cout<<dis[n*(k+1)+1]<<endl;
}

[JLOI2011]飞行路线 (分层图,最短路)的更多相关文章

  1. BZOJ2763: [JLOI2011]飞行路线(分层图 最短路)

    题意 题目链接 Sol 分层图+最短路 建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边 如果是取最大最 ...

  2. [JLOI2011]飞行路线 分层图最短路

    题目描述: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在nn个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一 ...

  3. P4568 [JLOI2011]飞行路线 分层图最短路

    思路:裸的分层图最短路 提交:1次 题解: 如思路 代码: #include<cstdio> #include<iostream> #include<cstring> ...

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

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

  5. 【bzoj2763】[JLOI2011]飞行路线 分层图最短路

    题目描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...

  6. BZOJ2763[JLOI2011]飞行路线 [分层图最短路]

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

  7. [bzoj2763][JLOI2011]飞行路线——分层图最短路

    水题.不多说什么. #include <bits/stdc++.h> using namespace std; const int maxn = 10010; const int maxk ...

  8. bzoj2763 [JLOI]飞行路线 分层图最短路

    问题描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...

  9. P4568 飞行路线 分层图最短路

    P4568 飞行路线 分层图最短路 分层图最短路 问题模型 求最短路时,可有\(k\)次更改边权(减为0) 思路 在普通求\(Dijkstra\)基础上,\(dis[x][j]\)多开一维\(j\)以 ...

随机推荐

  1. cv2.Canny 边缘检测

    Canny边缘检测   Canny 的目标是找到一个最优的边缘检测算法,最优边缘检测的含义是: 好的检测 - 算法能够尽可能多地标识出图像中的实际边缘. 好的定位 - 标识出的边缘要尽可能与实际图像中 ...

  2. Js 数组去重的几种方法总结

           去重是开发中经常会碰到的一一个热点问题,不过目前项目中碰到的情况都是后台接口使用SQL去重,简单高效,基本不会让前端处理去重.那么前端处理去重会出现什么情况呢?假如每页显示10条不同的数 ...

  3. NOIP模拟赛 双色球

    [题目描述] 机房来了新一届的学弟学妹,邪恶的chenzeyu97发现一位学弟与他同名,于是他当起了善良的学长233 “来来来,学弟,我考你道水题检验一下你的水平……” 一个栈内初始有n个红色和蓝色的 ...

  4. Java中的==和equals的区别详解

    1.基础知识 (1)String x = "hello"; (2)String x = new String ("hello"); 第1种方式的工作机制是,首先 ...

  5. [BZOJ] 1127: [POI2008]KUP

    似曾相识的感觉 考虑另一个判断问题,给定一个k,问这个k是否可行 存在矩形和\(sum>2k\),则该矩阵不对判定做出贡献 存在矩形和\(sum\in [k,2k]\),则我们找到了一个解 于是 ...

  6. php 关于金额的几种计算方式

    php 关于金额的几种计算方式 平常开始开发过程中,多多少少都会遇到点关于金额的计算,比如设置返利.提现手续费.折扣啊等等诸如此类的比例,然后再计算出之后的实际的费用. 下面,以折扣为例,来实现这类计 ...

  7. yield关键字有什么作用

    所属网站分类: python基础 > 语句 作者:goodbody 链接: http://www.pythonheidong.com/blog/article/10/ 来源:python黑洞网  ...

  8. Tomcat Bug记录

    1.问题:org.apache.tiles.request.render.CannotRenderException: ServletException including path '/WEB-IN ...

  9. LeetCode (160) Intersection of Two Linked Lists

    题目 Write a program to find the node at which the intersection of two singly linked lists begins. For ...

  10. HDU:4185-棋盘游戏

    棋盘游戏 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Problem Descri ...