BZOJ 2763: [JLOI2011]飞行路线 最短路
2763: [JLOI2011]飞行路线
Time Limit: 1 Sec
Memory Limit: 256 MB
题目连接
http://www.lydsy.com/JudgeOnline/problem.php?id=2763
Description
Alice和Bob现在要乘飞机旅行,他们选择了一家相对便宜的航空公司。该航空公司一共在n个城市设有业务,设这些城市分别标记为0到n-1,一共有m种航线,每种航线连接两个城市,并且航线有一定的价格。Alice和Bob现在要从一个城市沿着航线到达另一个城市,途中可以进行转机。航空公司对他们这次旅行也推出优惠,他们可以免费在最多k种航线上搭乘飞机。那么Alice和Bob这次出行最少花费多少?
Input
Output
只有一行,包含一个整数,为最少花费。
Sample Input
5 6 1
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.
题意
题解:
最短路,在转移dis的时候多开一维k就好了
dis[i][j]->dis[t][j]+e[i][t]
dis[i][j]->dis[t][j+1] if j<k
代码:
//qscqesze
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <bitset>
#include <vector>
#include <sstream>
#include <queue>
#include <typeinfo>
#include <fstream>
#include <map>
#include <stack>
typedef long long ll;
using namespace std;
//freopen("D.in","r",stdin);
//freopen("D.out","w",stdout);
#define sspeed ios_base::sync_with_stdio(0);cin.tie(0)
#define maxn 100010
#define eps 1e-9
int Num;
//const int inf=0x7fffffff; //§ß§é§à§é¨f§3
const int inf=0x3f3f3f3f;
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
//************************************************************************************** struct node
{
int x,y;
};
int dis[maxn][];
vector<node> E[maxn];
int inq[maxn][];
int main()
{
int n=read(),m=read(),k=read(),s=read(),t=read(); for(int i=;i<m;i++)
{
int x=read(),y=read(),z=read();
E[x].push_back((node){y,z});
E[y].push_back((node){x,z});
} for(int i=;i<=n;i++)
for(int j=;j<=k;j++)
dis[i][j]=inf; queue<node> Q;
Q.push((node){s,});
dis[s][]=;
int ans = inf;
while(!Q.empty())
{
node now = Q.front();
Q.pop();
inq[now.x][now.y]=;
for(int i=;i<E[now.x].size();i++)
{
if(dis[now.x][now.y]+E[now.x][i].y<dis[E[now.x][i].x][now.y])
{
dis[E[now.x][i].x][now.y]=dis[now.x][now.y]+E[now.x][i].y;
if(!inq[E[now.x][i].x][now.y])
{
inq[E[now.x][i].x][now.y]=;
Q.push((node){E[now.x][i].x,now.y});
}
}
if(dis[now.x][now.y]<dis[E[now.x][i].x][now.y+]&&now.y<k)
{
dis[E[now.x][i].x][now.y+]=dis[now.x][now.y];
if(!inq[E[now.x][i].x][now.y+])
{
inq[E[now.x][i].x][now.y+] = ;
Q.push((node){E[now.x][i].x,now.y+});
}
}
}
}
for(int i=;i<=k;i++)
ans = min(ans,dis[t][i]);
cout<<ans<<endl;
}
BZOJ 2763: [JLOI2011]飞行路线 最短路的更多相关文章
- 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1728 Solved: 649[Submit][Statu ...
- Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 1694 Solved: 635[Submit][Statu ...
- bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路
2763: [JLOI2011]飞行路线 Time Limit: 10 Sec Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...
- BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】
任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec M ...
- BZOJ 2763: [JLOI2011]飞行路线 spfa dp
题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=2763 题解: d[x][kk]表示从s到x用了kk次免费机会的最少花费. 代码: #in ...
- bzoj 2763 [JLOI2011]飞行路线——分层图
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...
- bzoj 2763: [JLOI2011]飞行路线
#include<cstdio> #include<cstring> #include<iostream> #include<queue> #defin ...
- bzoj 2763: [JLOI2011]飞行路线 分层图
题目链接 n个点m条路, 每条路有权值, 给出起点和终点, 求一条路使得权值最小.可以使路过的路中, k条路的权值忽略. 其实就是多一维, 具体看代码 #include<bits/stdc++ ...
随机推荐
- liunx之zip格式的解压命令
zip -r myfile.zip ./* 将当前目录下的所有文件和文件夹全部压缩成myfile.zip文件,-r表示递归压缩子目录下所有文件. 2.unzip unzip -o -d /home/s ...
- @section Right
布局页 _BaseLayout.cshtml @RenderSection("Right", true) 视图页 Index.cshtml @{ Layout = "~/ ...
- hdu 3938 Portal(并查集+离线+kruskal)2011 Multi-University Training Contest 10
搜了题解才把题搞明白.明白之后发现其实题意很清晰,解题思路也很清晰,只是题目表述的很不清晰…… 大意如下—— 给你一个无向图,图中任意两点的距离是两点间所有路径上的某一条边,这条边需要满足两个条件:1 ...
- hdu 2059(dp)
题意:容易理解... 思路:dp[i]表示乌龟到达第i个充电站时最少花费时间到第 i 个充电站后,从起点开始遍历到第 i-1 个充电站,得到最少花费时间 状态转移方程:dp[i]=min(dp[j]+ ...
- 2、列表item_圆头像_信息提示
import android.app.Activity; import android.os.Bundle; import android.view.LayoutInflater; import an ...
- 《零成本实现Web自动化测试--基于Selenium》第二章 Selenium简介和基础
第一部分 Selenium简介 1.Selenium 组建 1.1 Selenium-IDE Selenium-IDC是开发Selenium测试案例的集成开发环境.它像FireFox插件一样的工作,支 ...
- [Web API] 如何让 Web API 统一回传格式以及例外处理[转]
[Web API] 如何让 Web API 统一回传格式以及例外处理 前言 当我们在开发 Web API 时,一般的情况下每个 API 回传的数据型态或格式都不尽相同,如果你的项目从头到尾都是由你一个 ...
- Tsinsen A1303. tree(伍一鸣) (LCT+处理标记)
[题目链接] http://www.tsinsen.com/A1303 [题意] 给定一棵树,提供树上路径乘/加一个数,加边断边,查询路径和的操作. [思路] LCT+传标 一次dfs构造LCT. L ...
- 解决PHP5.3.x下ffmpeg安装配置问题
本人的环境: OS : windows 7 64位 WAMP:2.1a PHP:5.3.3(之前是5.3.13) 项目需要用ffmpeg-php实现上传视频转码截图等功能,但是找了很多资料都没有把ff ...
- MFC 解析xml文件
CComVariant IXMLDOMElement http://blog.sina.com.cn/s/blog_69e905cd0100kp5i.html