![](https://img-blog.csdnimg.cn/20201014180756928.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
SPFA
ToheartZhang
这个作者很懒,什么都没留下…
展开
-
洛谷 1073 最优贸易
//反BFS找能到终点的点,正BFS找到此点及以前最小代价。正BFS实际上是SPFA,要熟练掌握重复更新的思想。 #include<bits/stdc++.h> using namespace std; const int maxn = 100010; const int maxm = 500010; int n, m, tot, tot1, ans; int st[maxn], rst[maxn]原创 2017-08-16 16:32:29 · 268 阅读 · 0 评论 -
洛谷 1396 营救
//最小瓶颈路,用SPFA。 #include<bits/stdc++.h> using namespace std; const int maxn = 100010; int n, m, s, t, tot; int d[maxn], st[maxn];//d[]表示到该点路上最大值的最小值。 bool vis[maxn]; queue<int> q; struct node{ in原创 2017-08-16 17:21:48 · 372 阅读 · 0 评论 -
CodeVS 1242 布局
//差分约束系统 //以x-y <= k为例,等价于x <= k+y,相当于x和y之间的连边最大权值为k,然后跑最短路即知最大解。 //好久不做CodeVS了,洛谷大法好! #include<bits/stdc++.h> using namespace std; const int inf = 0x3f3f3f3f; queue<int> q; int n, m1, m2, tot; bool f原创 2017-08-24 10:46:16 · 266 阅读 · 0 评论 -
暑末 Day2 T1 Azuki has to work
//考试的时候把终点当成了n... //如果需要在城市群 a 与城市群 b 之间连一条长度为 c 的无向边,则我们连长度为 c 的有向边 outa → inb 和 outb → ina.容易发现这样建出的图和原图中城市互相可达的情况是等价的 // #include <bits/stdc++.h> #define debug(x) std::cerr << #x" = " << (x) << std原创 2017-08-29 17:11:16 · 368 阅读 · 0 评论 -
模板大集结!
好久不碰OI了,最近决定把各种基础算法的模板和用法整理下。·SPFA -求瓶颈路 洛谷 1396 -求最短路 好多。。 -路上最值 洛谷 1073 -边的特殊处理 eg. 加入点出点 暑末Day2 T1 -判负环 可结合分数规划食用#include<bits/stdc++.h> using namespace std;const int maxn =原创 2017-09-09 21:52:57 · 306 阅读 · 0 评论 -
1.2 最短路算法的多用
1.2.1 分算法之Dijkstra算法本质是贪心,一些不像图论的可贪心的让求关于单源的解的题也能用哦。不能解决负权边。 Eg1.佳佳的魔法药水 一道看起来和最短路没啥关系的题,但是可以贪心啊,每次找一个值最小但却没有确定最小值的药水,将其标记为最小值,然后枚举能与此药水合成药水的药水,用找到的药水与配对的药水更新合成药水的最小值,和Dij相似。 #include<bits/stdc++.h原创 2017-11-06 18:31:46 · 317 阅读 · 0 评论