【bzoj2763】[JLOI2011]飞行路线 分层图最短路
题目描述
输入
输出
样例输入
5 6 1
0 4
0 1 5
1 2 5
2 3 5
3 4 5
2 3 3
0 2 100
样例输出
8
题解
分层图Spfa
dis[i][j]表示免费j条后i到s的最短路。
然后跑分层图Spfa。
第一次写分层图,也是第一次用pair,所以代码略丑,凑合着看吧。
#include <cstdio>
#include <cstring>
#include <queue>
#include <utility>
using namespace std;
queue<pair<int , int> > q;
int head[10010] , to[100010] , len[100010] , next[100010] , cnt , dis[10010][11] , inq[10010][11];
void add(int x , int y , int z)
{
to[++cnt] = y;
len[cnt] = z;
next[cnt] = head[x];
head[x] = cnt;
}
int main()
{
int n , m , k , i , s , t , x , y , z , ans = 0x3f3f3f3f;
pair<int , int> u;
scanf("%d%d%d%d%d" , &n , &m , &k , &s , &t);
for(i = 1 ; i <= m ; i ++ )
scanf("%d%d%d" , &x , &y , &z) , add(x , y , z) , add(y , x , z);
memset(dis , 0x3f , sizeof(dis));
dis[s][0] = 0;
q.push(make_pair(s , 0));
while(!q.empty())
{
u = q.front();
q.pop();
x = u.first , y = u.second;
inq[x][y] = 0;
for(i = head[x] ; i ; i = next[i])
{
if(dis[to[i]][y] > dis[x][y] + len[i])
{
dis[to[i]][y] = dis[x][y] + len[i];
if(!inq[to[i]][y]) inq[to[i]][y] = 1 , q.push(make_pair(to[i] , y));
}
if(y < k && dis[to[i]][y + 1] > dis[x][y])
{
dis[to[i]][y + 1] = dis[x][y];
if(!inq[to[i]][y + 1]) inq[to[i]][y + 1] = 1 , q.push(make_pair(to[i] , y + 1));
}
}
}
for(i = 0 ; i <= k ; i ++ ) ans = min(ans , dis[t][i]);
printf("%d\n" , ans);
return 0;
}
【bzoj2763】[JLOI2011]飞行路线 分层图最短路的更多相关文章
- BZOJ2763: [JLOI2011]飞行路线(分层图 最短路)
题意 题目链接 Sol 分层图+最短路 建\(k+1\)层图,对于边\((u, v, w)\),首先在本层内连边权为\(w\)的无向边,再各向下一层对应的节点连边权为\(0\)的有向边 如果是取最大最 ...
- 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种航线,每种航线连接两个城市,并且航线有一定的 ...
- bzoj2763: [JLOI2011]飞行路线(分层图spfa)
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 3234 Solved: 1235[Submit][Stat ...
- [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]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 构建分层图. 代码如下: 写法1(空间略大)(时间很慢): #include<i ...
随机推荐
- DevExpress TreeList用法总结
http://blog.itpub.net/29251214/viewspace-774395/ http://blog.csdn.net/czp_huster/article/details/501 ...
- 优步UBER司机全国各地奖励政策汇总 (2月1日-2月7日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 成都Uber优步司机奖励政策(1月29日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- 安装MySQLdb模块遭遇"fatal error: my_config.h: No such file or directory"的处理
Issue I encountered an error when I run the python script which need to import the module of & ...
- Codeforces Round #495 (Div. 2) Sonya and Matrix
正常没有正方形的限制下,值为i的点个数4i 那么从0开始遍历,第一个不为4i的值就是min(x, y) 由于对称性我们姑且令x为这个值 我们先列举n*m=t的各种情况 对于一对n, m.我们已经知道n ...
- lesson 19 A very dear cat
lesson 19 A very dear cat dear adj. 亲爱的:尊敬的:昂贵的 表示几乎不,很少的词语 rarely hardly seldom scarcely flat = apa ...
- 【outPut_Class 输出类】使用说明
对象:outPut 说明:定义输出结果类的相关操作.此对象的核心是[JSON]类,所以它继承了[JSON]类的所有方法 重要: 输出结果样式为XML时,自带根节点"root".输出 ...
- 总结获取原生JS(javascript)基本操作
var a = document.getElementByIdx_x_x("dom"); jsCopy(a);//调用清理空格的函数 var b = a.childNodes;// ...
- [ Continuously Update ] The Paper List of Image / Video Captioning
Papers Published in 2018 Convolutional Image Captioning - Jyoti Aneja et al., CVPR 2018 - [ Paper Re ...
- 为什么安装beego和框架的失败 以及常用命令
1.安装了几个版本,版本之间相互影响. 把没用的删掉 2.网上找的教程存在问题. 都是相互抄袭.最权威的还是官网. which go rm -rf test/ echo path 获取路径 vim ~ ...