示例:

输入:

3 2 1 3 1
1 2 1
2 3 2

输出:1

题意:求s,t最短路,可将k条边权值置零。

题解:分层图最短路原题

#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int maxn = 1e5+;
const int INF = 0x3f3f3f3f;
struct State
{
// 优先队列的结点结构体
int v, w, cnt; // cnt 表示已经使用多少次免费通行权限
State() {}
State(int v, int w, int cnt) : v(v), w(w), cnt(cnt) {}
bool operator<(const State &rhs) const
{
return w > rhs.w;
}
};
struct node
{
int v;
int w;
int next;
/* data */
} edge[maxn];
priority_queue<State>pq;
int n,t,m,k,u,v,w,s;
int cnt;
bool vis[maxn][];
int dis[maxn][];
int head[maxn]; void add(int u,int v,int w) //链式前向星存边
{
edge[cnt] = {v,w,head[u]};
head[u] = cnt++;
}
void dijkstra()
{
memset(dis, 0x3f, sizeof(dis));
dis[s][] = ;
pq.push(State(s, , )); // 到起点不需要使用免费通行权,距离为零
while (!pq.empty())
{
State top = pq.top();
pq.pop();
int u = top.v;
int nowCnt = top.cnt;
if (vis[u][nowCnt])
continue;
vis[u][nowCnt] = true; for (int i = head[u]; ~i; i = edge[i].next)
{
int v = edge[i].v, w = edge[i].w;
if (nowCnt < k && dis[v][nowCnt + ] > dis[u][nowCnt])
{
// 可以免费通行
dis[v][nowCnt + ] = dis[u][nowCnt];
pq.push(State(v, dis[v][nowCnt + ], nowCnt + ));
}
if (dis[v][nowCnt] > dis[u][nowCnt] + w)
{
// 不可以免费通行
dis[v][nowCnt] = dis[u][nowCnt] + w;
pq.push(State(v, dis[v][nowCnt], nowCnt));
}
}
}
} int main()
{
memset(head,-,sizeof (head));
scanf("%d%d%d%d%d",&n,&m,&s,&t,&k);
while (m--)
{
scanf("%d%d%d",&u,&v,&w);
add(u, v, w);
add(v, u, w);
}
int ans = INF;
dijkstra();
for (int i = ; i <= k; ++i)
ans = min(ans, dis[t][i]); // 对到达终点的所有情况取最优值
cout << ans << endl;
}

free(分层图最短路)(2019牛客暑期多校训练营(第四场))的更多相关文章

  1. 2019牛客暑期多校训练营(第九场)A:Power of Fibonacci(斐波拉契幂次和)

    题意:求Σfi^m%p. zoj上p是1e9+7,牛客是1e9:  对于这两个,分别有不同的做法. 前者利用公式,公式里面有sqrt(5),我们只需要二次剩余求即可.     后者mod=1e9,5才 ...

  2. 2019牛客暑期多校训练营(第一场)A题【单调栈】(补题)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 题目描述 Two arrays u and v each with m distinct elem ...

  3. 2019牛客暑期多校训练营(第一场) B Integration (数学)

    链接:https://ac.nowcoder.com/acm/contest/881/B 来源:牛客网 Integration 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 5242 ...

  4. 2019牛客暑期多校训练营(第一场) A Equivalent Prefixes ( st 表 + 二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A 来源:牛客网 Equivalent Prefixes 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/ ...

  5. 2019牛客暑期多校训练营(第二场)F.Partition problem

    链接:https://ac.nowcoder.com/acm/contest/882/F来源:牛客网 Given 2N people, you need to assign each of them ...

  6. 2019牛客暑期多校训练营(第一场)A Equivalent Prefixes(单调栈/二分+分治)

    链接:https://ac.nowcoder.com/acm/contest/881/A来源:牛客网 Two arrays u and v each with m distinct elements ...

  7. [状态压缩,折半搜索] 2019牛客暑期多校训练营(第九场)Knapsack Cryptosystem

    链接:https://ac.nowcoder.com/acm/contest/889/D来源:牛客网 时间限制:C/C++ 2秒,其他语言4秒 空间限制:C/C++ 262144K,其他语言52428 ...

  8. 2019牛客暑期多校训练营(第二场)J-Subarray(思维)

    >传送门< 前言 这题我前前后后看了三遍,每次都是把网上相关的博客和通过代码认真看了再思考,然并卵,最后终于第三遍也就是现在终于看懂了,其实懂了之后发现其实没有那么难,但是的的确确需要思维 ...

  9. 2019牛客暑期多校训练营(第二场)D bitset

    题意 给一个n个结点的带点权的图,找到第k小的团的权值 分析 用bitset表示团的状态,一个结点必须和团里的每个结点都连边才能加进去,所以可以直接用\(\&\)运算来判断一个结点是否能加进去 ...

  10. 2019牛客暑期多校训练营(第一场)-A (单调栈)

    题目链接:https://ac.nowcoder.com/acm/contest/881/A 题意:给定两个长度均为n的数组a和b,求最大的p使得(a1,ap)和(b1,bp)等价,等价的定义为其任意 ...

随机推荐

  1. git的搭建和使用

    目录: 1.git与github介绍2.下载安装Git-20-64-bit.exe3.Git常用命令 git与github介绍 Git是什么 Git是一个开源的[分布式][版本控制系统],用于敏捷高效 ...

  2. WinDbg常用命令系列---日志操作相关命令log*

    .logopen (Open Log File) .logopen命令将事件和命令的副本从调试器命令窗口发送到新的日志文件. .logopen [Options] [FileName] .logope ...

  3. Codevs 2800 送外卖(状压DP)

    2800 送外卖 时间限制: 2 s 空间限制: 256000 KB 题目等级 : 钻石 Diamond 题目描述 Description 有一个送外卖的,他手上有n份订单,他要把n份东西,分别送达n ...

  4. 第03组 Alpha冲刺(1/4)

    队名:不等式方程组 组长博客 作业博客 团队项目进度 组员一:张逸杰(组长) 过去两天完成的任务: 文字/口头描述: 制定了初步的项目计划,并开始学习一些推荐.搜索类算法 GitHub签入纪录: 暂无 ...

  5. vue中使用vue-pdf插件显示pdf

    最近项目需求需要在vue中展示pdf,上网搜索了实现方法,找到vue-pdf这个插件非常好用,并且还有许多方法.属性能进行功能扩展. 一.安装 npm install --save vue-pdf 二 ...

  6. 差分形式的牛顿插值法(c++)

    本程序对cosx函数进行插值,取步长为0.1,因此x的值为0.00,0.10,0.20,0.30,对应的y值为cos(0.00),cos(0.10),cos(0.20),cos(0.30),其实本程序 ...

  7. Linux 磁盘格式化、检验、挂载

    分区完毕之后自然要进行文件系统的格式化.格式化命令mkfs(make file system)这个命令.这是个综合命令,它会去调用正确的文件系统格式化工具软件. 磁盘格式化 mkfs mke2fs m ...

  8. 使用OSCache优化性能,及JPA二级缓存

    1.使用静态化页面技术: 要统计产品的浏览次数: 在<body> <img src="http://www.site.com/data/count.do?productId ...

  9. mysql union all limit的使用

    To apply ORDER BY or LIMIT to an individual SELECT, place the clause inside the parentheses that enc ...

  10. Activiti task claim concurrent

    Activiti task claim cocurrent - 国内版 Binghttps://cn.bing.com/search?q=Activiti+task+claim+cocurrent&a ...