2763. [JLOI2011]飞行路线【分层图最短路】
Description
Input
Output
Sample Input
0 4
0 1 5
1 2 5
2 3 5
3 4 5
2 3 3
0 2 100
Sample Output
HINT
对于30%的数据,2<=n<=50,1<=m<=300,k=0;
对于50%的数据,2<=n<=600,1<=m<=6000,0<=k<=1;
对于100%的数据,2<=n<=10000,1<=m<=50000,0<=k<=10.
分层图最短路,感觉有种DP的思想
dis多开一维表示第几层的点
每一层的最短路只能向当前层转移,代价为边长
或者向下一层转移,代价为0
最多有k次代价为0的转移,符合题意
#include<iostream>
#include<cstring>
#include<cstdio>
#include<queue>
#define N (10000+100)
using namespace std;
int dis[][N],n,m,k,s,t;
int head[N],num_edge;
bool used[][N];
struct node1
{
int to,next,len;
}edge[N<<];
struct node
{
int dep,num;
};
queue<node>q; void add(int u,int v,int l)
{
edge[++num_edge].to=v;
edge[num_edge].next=head[u];
edge[num_edge].len=l;
head[u]=num_edge;
} void Spfa()
{
memset(dis,0x7f,sizeof(dis));
dis[][s]=;
used[][s]=true;
node x; x.dep=; x.num=s;
q.push(x);
while (!q.empty())
{
node x=q.front(); q.pop();
for (int i=head[x.num];i!=;i=edge[i].next)
for (int j=;j<=;++j)
{
if (x.dep==k+ && j==) continue;
if (dis[x.dep][x.num]+edge[i].len*(j^)<dis[x.dep+j][edge[i].to])
{
dis[x.dep+j][edge[i].to]=dis[x.dep][x.num]+edge[i].len*(j^);
if (!used[x.dep+j][edge[i].to])
{
used[x.dep+j][edge[i].to]=true;
node y; y.dep=x.dep+j; y.num=edge[i].to;
q.push(y);
}
} }
used[x.dep][x.num]=false;
}
} int main()
{
int u,v,l,ans=0x7fffffff;
scanf("%d%d%d%d%d",&n,&m,&k,&s,&t);
for (int i=;i<=m;++i)
{
scanf("%d%d%d",&u,&v,&l);
add(u,v,l); add(v,u,l);
}
Spfa();
for (int i=;i<=k+;++i)
ans=min(ans,dis[i][t]);
printf("%d",ans);
}
2763. [JLOI2011]飞行路线【分层图最短路】的更多相关文章
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- BZOJ2763[JLOI2011]飞行路线 [分层图最短路]
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 2523 Solved: 946[Submit][Statu ...
- 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> ...
- 【bzoj2763】[JLOI2011]飞行路线 分层图最短路
题目描述 Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司.该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的 ...
- bzoj 2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...
- [JLOI2011]飞行路线 (分层图,最短路)
题目链接 Solution 建立 \(k+1\) 层图跑 \(Dijkstra\) 就好了. Code #include<bits/stdc++.h> #define ll long lo ...
- bzoj 2763: [JLOI2011]飞行路线 分层图
题目链接 n个点m条路, 每条路有权值, 给出起点和终点, 求一条路使得权值最小.可以使路过的路中, k条路的权值忽略. 其实就是多一维, 具体看代码 #include<bits/stdc++ ...
- [bzoj2763][JLOI2011]飞行路线——分层图最短路
水题.不多说什么. #include <bits/stdc++.h> using namespace std; const int maxn = 10010; const int maxk ...
随机推荐
- Springboot @ResponseBody返回中文乱码
最近我在把Spring 项目改造Springboot,遇到一个问题@ResponseBody返回中文乱码,因为response返回的content-type一直是application/json;ch ...
- 后台数据校验-BeanCheck
package com.ldf.domain; import java.text.ParseException; public class UserCheck { //从表单获取的数据 private ...
- 【SSH网上商城项目实战08】查询和删除商品类别功能的实现
转自:https://blog.csdn.net/eson_15/article/details/51338991 上一节我们完成了使用DataGrid显示所有商品信息,这节我们开始添加几个功能:添加 ...
- unity3d之使用技巧
知乎 project.hierarchy折叠打开全部文件夹——alt +方向键
- python中字典,没键加键,有键操作其键对应的值,的思想
cars = ['鲁A32444', '鲁B12333', '京B8989M', '黑C49678', '黑C46555', '沪B25041', '黑C34567'] locations = {'沪 ...
- 纯css 画气泡
我们知道运用css可以绘画出各式各样的形状:三角形,圆形,正方形,椭圆形,平行四边形等等,而通过他们之间进行两两组合可以变换出各种意想不到的效果图,气泡框就是其中一个.最简单的气泡框就是一个矩形框+一 ...
- 实现键盘记录的e.Whick和keyCode,兼容FireFox和IE
主要分四个部分第一部分:浏览器的按键事件第二部分:兼容浏览器第三部分:代码实现和优化第四部分:总结 第一部分:浏览器的按键事件 用js实现键盘记录,要关注浏览器的三种按键事件类型,即keydown,k ...
- 移动目标在三维GIS中的实现方法
对于基于ArcGIS Runtime的应用程序,其实现方法比较简单,可以直接更新图形的Geometry属性,即可实现位置的移动: private void AddGraphics() { var gl ...
- Google APAC----Africa 2010, Qualification Round(Problem B. Reverse Words)----Perl 解法
原题地址链接:https://code.google.com/codejam/contest/351101/dashboard#s=p1 问题描述: Problem Given a list of s ...
- Android ImageSpan的使用
编辑框中加图片 代码如下: mSubjectDetailView = (TextView) findViewById(R.id.subject_detail); CharSequence text = ...