随笔分类 -  图论

摘要:原题链接:POJ3259解析:找了四五小时bug,打错俩个字母,想吃口屎冷静一下。代码示例:#include#include#include#include#includeusing namespace std;const int INF = 2e9;const in... 阅读全文
posted @ 2018-08-27 16:27 Dr_Lo 阅读(77) 评论(0) 推荐(0)
摘要:原题链接:HDOJ2586解析:用树上倍增法来求LCA代码实例:#include#include#include#include#includeusing namespace std;const int maxn = 40010;int f[maxn][20],d[m... 阅读全文
posted @ 2018-08-27 15:25 Dr_Lo 阅读(159) 评论(0) 推荐(0)
摘要:1.Bellmen-Ford判定负环思路:若经过n轮迭代,算法仍未结束(仍有能产生更新的边),则图中存在负环 若n - 1轮迭代之内,算法结束(所有边满足三角不等式),则图中无负环2.SPFA判定负环思路:设cnt[x]表示从1到x的最短路径包含的边数,cnt[1] ... 阅读全文
posted @ 2018-08-27 09:16 Dr_Lo 阅读(192) 评论(0) 推荐(0)
摘要:代码出自:《算法竞赛入门经典——训练指南》P328#include#include#include#includeusing namespace std;const int maxn = 10005;const int INF = 2147483647;struct ... 阅读全文
posted @ 2018-08-24 15:05 Dr_Lo 阅读(533) 评论(0) 推荐(0)
摘要:原题链接:POJ1287解析:这题我用来练习Prim算法的,算是当作一个模板来看。以下代码有几点要说明的:我使用了优先队列,并没有使用dist[u]数组来保存当前子树到 u 的最短距离,这样省去了找最短路的时间 由于队列中存放的最短距离,可能该点已经存在子树中了,所以... 阅读全文
posted @ 2018-08-23 11:08 Dr_Lo 阅读(113) 评论(0) 推荐(0)