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

数据的第一行有三个整数,n,m,k,分别表示城市数,航线数和免费乘坐次数。
第二行有两个整数,s,t,分别表示他们出行的起点城市编号和终点城市编号。(0<=s,t<n)
接下来有m行,每行三个整数,a,b,c,表示存在一种航线,能从城市a到达城市b,或从城市b到达城市a,价格为c。(0<=a,b<n,a与b不相等,0<=c<=1000)

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

8

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; //§&szlig;§é§à§é¨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]飞行路线 最短路的更多相关文章

  1. 分层图+最短路算法 BZOJ 2763: [JLOI2011]飞行路线

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...

  2. Bzoj 2763: [JLOI2011]飞行路线 dijkstra,堆,最短路,分层图

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1728  Solved: 649[Submit][Statu ...

  3. Bzoj 2763: [JLOI2011]飞行路线 拆点,分层图,最短路,SPFA

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 1694  Solved: 635[Submit][Statu ...

  4. bzoj 2763: [JLOI2011]飞行路线 -- 分层图最短路

    2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  Memory Limit: 128 MB Description Alice和Bob现在要乘飞机旅行,他们选择了一家相 ...

  5. BZOJ 2763: [JLOI2011]飞行路线 【分层图模板】

    任意门:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 2763: [JLOI2011]飞行路线 Time Limit: 10 Sec  M ...

  6. BZOJ 2763: [JLOI2011]飞行路线 spfa dp

    题目链接: http://www.lydsy.com/JudgeOnline/problem.php?id=2763 题解: d[x][kk]表示从s到x用了kk次免费机会的最少花费. 代码: #in ...

  7. bzoj 2763 [JLOI2011]飞行路线——分层图

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=2763 分层图两种方法的练习. 1.把图分成k+1层,本层去上面一层的边免费.但空间时间都不算 ...

  8. bzoj 2763: [JLOI2011]飞行路线

    #include<cstdio> #include<cstring> #include<iostream> #include<queue> #defin ...

  9. bzoj 2763: [JLOI2011]飞行路线 分层图

    题目链接 n个点m条路, 每条路有权值,  给出起点和终点, 求一条路使得权值最小.可以使路过的路中, k条路的权值忽略. 其实就是多一维, 具体看代码 #include<bits/stdc++ ...

随机推荐

  1. ios第三方开源库

    1.AFNetworking 目前比较推荐的iOS网络请求组件,默认网络请求是异步,通过block回调的方式对返回数据进行处理. 2.FMDB 对sqlite数据库操作进行了封装,demo也比较简单. ...

  2. elementaryOS系统托盘解决方案

    在用 eOS 的时候,你可能会遇到系统托盘的问题,有些需要托盘的软件比如说 QQ,没办法在 eOS 的 Wingpanel 上显示,一最小化就不见了,或者出现一个 System tray 的窗口,很麻 ...

  3. [转] C# 中的static静态变量

    logitechyan原文关于C#中static静态变量 C#静态变量使用static 修饰符进行声明,在类被实例化时创建,通过类进行访问不带有 static 修饰符声明的变量称做非静态变量,在对象被 ...

  4. DevExpress控件XtraGrid的Master-Detail用法 z

    XtraGrid支持Master-Detail展示,在自带的Demo中展示了一个“公司——产品——订单”的例子.自己照着实现了一下,有几处关键地方补充一下. 示例: 部门信息(主1)——部门下用户(从 ...

  5. XTUOJ1247 Pair-Pair 预处理+暴力

    分析:开个1000*1000的数组,预处理矩阵和,然后分类讨论就好 时间复杂度:O(n) #include <cstdio> #include <iostream> #incl ...

  6. C语言中 v...printf类函数的用法

    C语言的自学渐渐接近尾声,今天学到了标准库中的stdarg.h头,里面关联了stdio.h头里面的一类函数:v...printf函数,里面举的例子看了之后还是不太明白,google了一下依旧不是很懂, ...

  7. <Chapter 2>2-1-1.安装Python SDK

    App Engine包含两个Python运行时环境:一个基于Python2.5的传统环境,以及一个运行Python2.7的新环境.这个新环境不仅仅是有一个轻微的新版本的Python解释器.主要是,这个 ...

  8. spice

    the following diagram illustrates VD-Interface illustrates display portemphasizing   emphasizing   e ...

  9. 【转】Maven实战(七)---传递依赖

    原博文出自于:http://blog.csdn.net/liutengteng130/article/details/47000069   感谢! 假设A-->C  B-->A      ...

  10. Homework-10 BASIC

    对于本次作业: 我的整体思路如下: 1.首先修改二维数组求最大子数组和的C语言代码,加入分步骤的当前最优解边界值,局部最优解的记录,使之支持分步执行,连续执行,回滚等功能. 2.将程序改写为Javas ...