题目链接


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. xpath定位和css定位对比

    xpath定位和css定位对比   实际项目中使用较多的是xpath定位和css定位.XPath是XML文档中查找结点的语法,换句话就是通过元素的路径来查找这个元素.xpath比较强大,而css选择器 ...

  2. C++容器类-vector

    vecto之简单应用: #include<vector> #include<iostream> using namespace std; int main() { vector ...

  3. equals和HashCode的羁绊

    equals和hashcode我一直没弄明白到底怎么回事,今天终于弄懂了. 如下图: 在Person类没有重写equals和hashcode方法时,是如下情况: 但是当我重写了equals方法时,是如 ...

  4. POP简单动画简单使用 (入门级别)

    动画可以让APP“更友好”的与用户交互,苹果提供很多的好看的动画供开发者使用,不过简单的平移.旋转.缩放.......使用起来很简单,但是想要进行一些比较复杂的动画效果,使用起来就比较难以实现,俗话说 ...

  5. A. Vitya in the Countryside

    A. Vitya in the Countryside time limit per test 1 second memory limit per test 256 megabytes input s ...

  6. 对O(logN)复杂度的推导

    之前一直对O(logN)这个复杂度如何推导出的存在疑问,这段时间看了一些算法相关的内容,正好看到这个问题,大略研究了一下算是基本解答了我的疑惑:现记录如下 假设有一棵高为H的满二叉树,则它的节点共有N ...

  7. rest_framework之status HTTP状态码

    Django Rest Framework有一个status.py的文件 通常在我们Django视图(views)中,HTTP状态码使用的是纯数字,像400,404,200,304等,并不是那么很好理 ...

  8. 【Maven】 (请使用 -source 8 或更高版本以启用 lambda 表达式)

    在使用mvn install编译maven项目时,报了 “ (请使用 -source 8 或更高版本以启用 lambda 表达式)”错误,是因为设置的maven默认jdk编译版本太低的问题. 可使用两 ...

  9. paper:synthesizable finit state machine design techniques using the new systemverilog 3.0 enhancements之enhanced coding styles

    1.ANSI style 的代码比较紧凑. 下面规范推荐,比较好. 下面是带有parameter的module header的完整规范 一般1bit ,大家都是wire signal1 = gen_s ...

  10. 阿里云全国快递物流查询api接口

    口地址: https://market.aliyun.com/products/56928004/cmapi021863.html?spm=5176.730005.productlist.d_cmap ...