摘要: 关于SLF优化 朴素SPFA使用常规队列(FIFO)更新距离,并没有考虑优化出队顺序( 值小的优先出队)可以在一开始就把各个点的 值限值小,从而避免大量的松弛操作,从而提高效率。这就是 。 实现方式很简单,常规队列替换为双端队列( ),对于一个要加入的点 ,如果`dis[u] 全称:“double 阅读全文
posted @ 2019-03-08 10:43 LFYZOI题解 阅读(554) 评论(0) 推荐(0) 编辑
摘要: ```cpp //时间复杂度:O(NM) //动态规划思想 //可以处理负边,可以检测出负环 include include using namespace std; const int maxn=1010, maxm=10010, INF=0x3f3f3f3f; int n, m, s, dis[ 阅读全文
posted @ 2019-03-06 09:25 LFYZOI题解 阅读(196) 评论(0) 推荐(0) 编辑
摘要: ```cpp //仅适用于点非常少的情况,n不超过几百 //floyd使用了动态规划思想,可以处理负边,但不能处理有负环的情况 //适用于使用邻接矩阵存储 for(k=1; ke[i][k]+e[k][j]) e[i][j]=e[i][k]+e[k][j]; ``` 阅读全文
posted @ 2019-03-06 08:53 LFYZOI题解 阅读(172) 评论(0) 推荐(0) 编辑
摘要: ```cpp include include include include include using namespace std; typedef pair pii; const int maxn=1e5+5, maxm=2e5+5; struct edge { int t, w; edge n 阅读全文
posted @ 2019-03-06 08:39 LFYZOI题解 阅读(549) 评论(0) 推荐(0) 编辑
摘要: ```cpp int read() { int w=1, s=0; char ch=getchar(); while(ch'9') { if(ch==' ') w= 1; ch=getchar(); } while(ch ='0'&& ch 阅读全文
posted @ 2019-03-05 17:09 LFYZOI题解 阅读(246) 评论(0) 推荐(0) 编辑
摘要: ```cpp include include include include using namespace std; const int maxn = 1e4 + 5; int f[maxn]; int n, m; inline int Find(int x) { return f[x] == x 阅读全文
posted @ 2019-03-05 17:02 LFYZOI题解 阅读(116) 评论(0) 推荐(0) 编辑
摘要: 空间复杂度:O(N+E) 时间复杂度:O(ElogE) cpp include include include include using namespace std; const int maxn=5e3+5, maxm=2e5+5; int f[maxn], n, m; //f为并查集数组 st 阅读全文
posted @ 2019-03-05 08:47 LFYZOI题解 阅读(149) 评论(0) 推荐(0) 编辑
摘要: 内置类型 介绍 pair的应用 将两个数据合成一个数据(元组),方便使用。如当一个函数需要返回两个数据,可以返回pair类型。pair的实现是一个结构体。有两个成员:first,second。 make_pair函数 usage1: 灵活的方式,会自动进行类型转换,T1为int,T2为double 阅读全文
posted @ 2019-03-04 18:49 LFYZOI题解 阅读(968) 评论(0) 推荐(0) 编辑
摘要: ```cpp include include include include using namespace std; typedef long long ll; priority_queue, greater a; //greater表示从大到小排序,形成小根堆 //less表示从小到大排序,形成 阅读全文
posted @ 2019-03-04 12:05 LFYZOI题解 阅读(133) 评论(0) 推荐(0) 编辑
摘要: ```cpp include include using namespace std; const int maxn=1e5+5; int a[maxn], n; void adjust(int s, int t) { int dad=s; int son=dad 2; while(sona[son 阅读全文
posted @ 2019-03-04 11:54 LFYZOI题解 阅读(148) 评论(0) 推荐(0) 编辑