[JLOI2011]飞行路线 (分层图,最短路)
题目链接
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]飞行路线 (分层图,最短路)的更多相关文章
- BZOJ2763: [JLOI2011]飞行路线(分层图 最短路)
题意 题目链接 Sol 分层图+最短路 建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边 如果是取最大最 ...
- [JLOI2011]飞行路线 分层图最短路
题目描述: Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在nn个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一 ...
- P4568 [JLOI2011]飞行路线 分层图最短路
思路:裸的分层图最短路 提交:1次 题解: 如思路 代码: #include<cstdio> #include<iostream> #include<cstring> ...
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- 【bzoj2763】[JLOI2011]飞行路线 分层图最短路
题目描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2523 Solved: 946[Submit][Statu ...
- [bzoj2763][JLOI2011]飞行路线——分层图最短路
水题.不多说什么. #include <bits/stdc++.h> using namespace std; const int maxn = 10010; const int maxk ...
- bzoj2763 [JLOI]飞行路线 分层图最短路
问题描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...
- P4568 飞行路线 分层图最短路
P4568 飞行路线 分层图最短路 分层图最短路 问题模型 求最短路时,可有\(k\)次更改边权(减为0) 思路 在普通求\(Dijkstra\)基础上,\(dis[x][j]\)多开一维\(j\)以 ...
随机推荐
- Spring归纳
Spring总结 bean标签的scope属性 scope="singleton",单例模式,默认值 scope="prototype",多例模式 注解元素 @ ...
- 常用的ement语法
缩写语法: 介绍:Emmet 使用类似于 CSS 选择器的语法描述元素在生成的文档树中的位置及其属性. 声明:第一次写博客大家多多关照,如有错误或者需要补充的请到评论里留言,谢谢大家! 快速生成htm ...
- HTML5<section>元素
HTML5<section>元素用来定义页面文档中的逻辑区域或内容的整合(section,区域),比如章节.页眉.页脚或文档中的其他部分. 根据W3C HTML5文档中:section里面 ...
- centos 7 忘记root 密码
@@@@首先开启系统,出现下图界面以后,按e键. @@@使用下放下箭头找到图中的位置,在下图中 修改 ro 为 rw , 添加init=sysroot/bin/sh @@@按Ctrl + x 进入单用 ...
- 【laravel】laravel class 里面定义以head开头的方法会报错
BadMethodCallException in Macroable.php line 81:Method head does not exist.
- Linux安装配置***客户端
1.创建root用户 sudo passwd root su root 2.安装shadowsocks sudo apt-get install python-pip sudo pip install ...
- w3resource_MySQL练习:Basic_select_statement
w3resource_MySQL练习题:Basic_select_statement 1. Write a query to display the names (first_name, last_n ...
- init_bootmem_node
初始化pg_data_t->bdtat结构体, /* * node_bootmem_map is a map pointer - the bits represent all physical ...
- poj 3176 三角数和最大问题 dp算法
题意:给一个三角形形状的数字,从上到下,要求数字和最大 思路 :dp dp[i+1][j]=max(dp[i+1][j],dp[i][j]+score[i+1][j]) dp[i+1][j+1]=ma ...
- HTTP和HTTPS以及两者的区别
HTTP:是互联网上的应用广泛的一种网络协议,是一个客户端和服务器端请求和应答的传输协议,它可以使浏览器更加高效,使网络传输减少. HTTPS:是以安全为目标的HTTP通道,简单讲是HTTP的安全版, ...