
【最短路】
文章平均质量分 92
墓华
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
同余最短路(洛谷P2371 墨墨的等式)
定义 同余最短路常用于解决这样一类问题: 有nnn个正整数a1,a2,a3,⋯ ,ana_1, a_2,a_3 , \cdots, a_na1,a2,a3,⋯,an,设: x1a1+x2a2+x3a3+⋯+xnan=k (x1,x2,x3,⋯ ,xn∈N)x_1a_1+x_2a_2+x_3a_3+\cdots+x_na_n=k\;\;\;\;\;\;\;\...原创 2020-04-07 14:08:59 · 391 阅读 · 0 评论 -
CodeForces - 1206D Shortest Cycle(位运算,floyd求无向图最小环)
链接:CodeForces - 1206D Shortest Cycle 题意: 给出n  (≤105)n\;(\le 10^5)n(≤105)个数 a1,a2,…,an  (ai≤1018)a_1,a_2,\dots,a_n\;(a_i\le10^{18})a1,a2,…,an(ai≤1018),表示图中nnn个结点,若ai∧aj≠...原创 2019-08-20 17:02:28 · 371 阅读 · 0 评论 -
图论 —— floyd算法(全源最短路问题 / 无向图找最小环)
floyd算法: 对于一个含有nnn个结点的无负环图GGG(通常用邻接矩阵存储),floyd算法可以用于解决全源最短路问题,和查找无向图中最小环,时间复杂度O(n3)O(n^3)O(n3), ①全源最短路问题: 邻接矩阵g[i][j]g[i][j]g[i][j]:表示边i→ji\rarr ji→j的距离,INF表示i,ji,ji,j之间无边直接相连 dist[i][j]dist[i][j]di...原创 2019-08-20 16:19:29 · 1335 阅读 · 0 评论 -
2019多校第一场 HDU6582 - Path(最短路,最小割)
链接:HDU6582 - Path 题意: 给出一张含有n个结点、m条边有向图,要求删除边使得 1 -> n 最短路的总长增大(或无法到达),删除的花费即边的长度,问最小花费为多少。 分析: 很容易想到把最短路全部拎出来建个新图,然后用网络流求最小割。 但是比较麻烦的就是跑完最短路以后怎么把 所有的1 -> n 的最短路 都拎出来。 看到别人的方法是,分别从点1和点n开始跑两遍最短...原创 2019-07-23 22:49:54 · 311 阅读 · 0 评论 -
I - Arbitrage(判断正环,SPFA算法)
链接:Arbitrage Arbitrage is the use of discrepancies in currency exchange rates to transform one unit of a currency into more than one unit of the same currency. For example, suppose that 1 US Dollar b...原创 2019-03-01 20:35:47 · 440 阅读 · 0 评论 -
H - Cow Contest(全源最短路,Floyd算法)
链接:Cow Contest N (1 ≤ N ≤ 100) cows, conveniently numbered 1…N, are participating in a programming contest. As we all know, some cows code better than others. Each cow has a certain constant skill ra...原创 2019-02-28 19:51:19 · 298 阅读 · 0 评论 -
F - Wormholes(负环判断,BF算法 / SPFA算法)
链接:Wormholes While exploring his many farms, Farmer John has discovered a number of amazing wormholes. A wormhole is very peculiar because it is a one-way path that delivers you to its destination at...原创 2019-02-27 22:03:06 · 397 阅读 · 0 评论 -
Bellman-Ford算法、SPFA算法模板——含负边权单源最短路问题 及 负环判断问题
Bellman-Ford算法: 核心思路: 源点d值设为0,其他d值设为INF。执行N-1次操作(N为结点数),每次遍历所有边来进行松弛操作。N-1次操作结束后,再遍历一次所有边,若还能继续松弛,说明有源点可达的负环。 模板: struct edge { int u; int v; int w; } a[maxm]; int N,M; //N个结点,M条边 int d[maxn]...原创 2019-02-27 20:08:36 · 355 阅读 · 0 评论 -
C - Heavy Transportation(最短路变形 / 最大生成树)
链接:Heavy Transportation Background Hugo Heavy is happy. After the breakdown of the Cargolifter project he can now expand business. But he needs a clever man who tells him whether there really is a wa...原创 2019-02-26 13:02:53 · 612 阅读 · 0 评论 -
PAT Advanced 1072 Gas Station(图,最短路)
链接:PAT Advanced 1072 A gas station has to be built at such a location that the minimum distance between the station and any of the residential housing is as far away as possible. However it must guar...原创 2019-02-08 14:45:59 · 245 阅读 · 0 评论 -
Dijkstra算法模板及其优先队列优化~~
Dijkstra算法:用于解决 非负路权 单源 最短路问题 无优化的Dijkstra算法 int N, G[maxn][maxn] = { 0 }; //N为结点数目(编号0 ~ N-1) int d[maxn], pre[maxn]; //G为邻接矩阵,G[u][v]=0表示 u、v无通路 bool vis[maxn] = { false }; void Dijkstra(i...原创 2019-02-08 12:27:26 · 1715 阅读 · 4 评论 -
SPFA以及其优化
SPFA(Shortest Path Faster Algorithm)是Bellman-Ford算法的一种队列实现,减少了不必要的冗余计算。 SPFA,要从Bellman-ford的优化说起。在n个点m条边的图中,Bellman-ford的复杂度是n*m,依次对每条边进行松弛操作,重复这个操作n-1次后则一定得到最短路,如果还能继续松弛,则有负环。这是因为最长的没有环路的路,也只不过是n个点n...转载 2019-01-31 11:59:00 · 323 阅读 · 0 评论 -
PAT Advanced 1030 Travel Plan(图,最短路径,Dijkstra算法)
链接:PAT Advanced 1030 A traveler’s map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a program to help a traveler to deci...原创 2019-01-29 11:42:52 · 200 阅读 · 0 评论 -
牛客小白月赛16 J-小雨坐地铁(分层图最短路)
链接:https://ac.nowcoder.com/acm/contest/949/J 来源:牛客网 题目描述 小雨所在的城市一共有 m 条地铁线,分别标号为 1 号线,2 号线,……,m 号线。整个城市一共有 n 个车站,编号为 1∼n。其中坐 i 号线需要花费 ai 的价格,每坐一站就需要多花费 bi 的价格。i 号线有 ci 个车站,而且这 ci 个车站都已知,如果某一站有多条地铁线经过...原创 2019-07-14 17:33:41 · 581 阅读 · 0 评论