SPFA
最短路
VL——MOESR
ga
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
【2022年11月22日提高A组】数论计算【SPFA】【数学】
spfa + 数学原创 2022-11-22 15:51:46 · 150 阅读 · 0 评论 -
【集训DAY3】 Reconstruction of roads【SPFA】
spfa原创 2022-07-13 19:13:23 · 142 阅读 · 0 评论 -
2021.08.24【NOIP提高A、B组】模拟 Party
思路: 正反边跑spfa codecodecode #include<iostream> #include<cstring> #include<cstdio> #include<queue> using namespace std; int n, m, t; int dis[10010], dis1[10010]; int head[10010], tot, head1[10010], tot1; bool v[10010]; struct node..原创 2021-08-24 16:42:10 · 113 阅读 · 0 评论 -
Luogu_【P7297】P7297 【USACO】 Telephone G
思路: 暴力建图会炸,然后就建一个分层图跑spfa codecodecode #include<iostream> #include<cmath> #include<cstdio> #include<cstring> #include<queue> using namespace std; int n, k, tot; int a[101010]; bool b[100][100]; int dis[25010000], head[250..原创 2021-08-17 16:43:13 · 174 阅读 · 0 评论 -
【YBTOJ】最优贸易
思路: 我们直接考虑一个中转点,从1到它的最小买入值是多少,和它到n的最大卖出值,然后相减得出答案 此过程就用两个spfa来解决 codecodecode #include<iostream> #include<queue> #include<cstdio> using namespace std; int n, m, tot1, tot; int a[100100]; struct node { int to, next, w; }b[1001000], b..原创 2021-05-03 19:40:45 · 165 阅读 · 0 评论 -
【YBTOJ】判断负环
思路: 直接暴力跑spfa,如果一个点被走过太多次,那么就有负环 codecodecode #include<iostream> #include<cstdio> #include<queue> #include<cstring> using namespace std; long long n, m, tot; long long head[50010], dis[50010], d[50010]; bool v[50010]; queue<..原创 2021-04-17 07:52:25 · 191 阅读 · 0 评论 -
【YBTOJ】电路维修
思路: 乍一看这题,没有bfs的头绪 但是,我们想到了spfa 我们可以把地图中的每个点看成方格,这样就有(n+1)*(m+1)个方格 如果两点之间有线联通,那它们之间的边权就是0,否则就为1 然后spfa就可以了 codecodecode #pragma GCC optimize(2) #include<iostream> #include<cstdio> #include<cstring> using namespace std; int t, js; int ..原创 2021-01-20 20:01:25 · 236 阅读 · 0 评论 -
【LuoguP1629】邮递员送信
题目链接 题目大意: 让你求1到 2−N2-N2−N的路径和2−N2-N2−N到1的路径,然后加起来 思路: 起点为1的做法比较简单,可以用spfa来做 其实2−N2-N2−N到1的路径就把图反过来得到的值就是2−N2-N2−N到1的路径 代码: #include<iostream> #include<cstring> #include<cstdio> using namespace std; int n,m,dis[1010],dis1[1010],v[10010]原创 2020-07-20 21:59:21 · 122 阅读 · 0 评论 -
最优贸易
#include<iostream> #include<cstring> #include<cstdio> using namespace std; int m,n,k,a[100100],maxx[1000100],minn[1000100],v[1010001],f[1000100],ans; struct node{ int x,y,next,w; }x...原创 2020-01-16 20:57:46 · 420 阅读 · 1 评论 -
工厂的烦恼1762
Description 某工厂发现厂里的机器在生产产品时要消耗大量的原材料,也就是说,有大量的原材料变成了废物。因此厂里想找出消耗原材料最大的一条生产线路进行改造,以降低成本。厂里的生产线路是一个有向无环网络,有N台机器分别代表网络中的N个结点。弧< I,j >(i < j)表示原材料从机器i传输到机器j的损耗数量。 Input 第一行是两个整数N,M(N<=100,...原创 2020-01-15 21:11:30 · 177 阅读 · 0 评论 -
1761城市问题
Description 设有n个城市,依次编号为0,1,2,……,n-1(n<=100),另外有一个文件保存n个城市之间的距离(每座城市之间的距离都小于等于1000)。当两城市之间的距离等于-1时,表示这两个城市没有直接连接。求指定城市k到每一个城市i(0<=I,k<=n-1)的最短距离。 Input 第一行有两个整数n和k,中间用空格隔开;以下是一个NxN的矩阵,表示城市...原创 2019-12-28 15:52:43 · 188 阅读 · 0 评论 -
USACO 3.2 Sweet Butter 香甜的黄油
Description 农夫John发现做出全威斯康辛州最甜的黄油的方法:糖。把糖放在一片牧场上,他知道N(1<=N<=500)只奶牛会过来舔它,这样就能做出能卖好价钱的超甜黄油。当然,他将付出额外的费用在奶牛上。 农夫John很狡猾。像以前的Pavlov,他知道他可以训练这些奶牛,让它们在听到铃声时去一个特定的牧场。他打算将糖放在那里然后下午发出铃声,以至他可以在晚上挤奶。 ...原创 2019-12-28 10:44:59 · 294 阅读 · 0 评论
分享