![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
图论
SolarDomo
每天都被头像萌醒
展开
-
POJ 1125 最短路 FLOYD
题目链接求一个起点 这个起点到图中所有点的最大距离最短 水题不多说 代码:#include <cstdio>#include <iostream>#include <cstring>using namespace std;const int maxn = 105;const int INF = 0x3f3f3f3f;int Adj[maxn][maxn];int n;void F原创 2016-08-04 22:37:33 · 211 阅读 · 0 评论 -
SPOJ Count on a tree 在线LCA + 主席树
题意:求树上a , b路径上第k大的点 主席树a + 主席树b - 主席树(LCA(a,b)) - 主席树(FA(LCA(a,b)))代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 100000 + 50;/** 主席树 */const in原创 2016-10-13 22:12:50 · 338 阅读 · 0 评论 -
割点、割边、双连通分支
一、割点、割边、双连通分支概念挂接点(Articulation point)就是割点(Cut Vertex)桥(Bridge)就是割边(Cut Edge)割点:v为割点,则去掉v后,图的连通分支增加。割边:v为割边,则去掉v后,图的连通分支增加。割点形式化的定义:a是割点当且仅当存在两个点u,v使得u到v的每条路径都会经过a。(去掉a转载 2016-10-12 15:07:11 · 878 阅读 · 0 评论 -
POJ 1144 Network Tarjan 求无向图的割点的个数 Tarjan 模板题
题目链接:http://poj.org/problem?id=1144 题意:给你一个图 求这个图上的割点的个数代码://#include <bits/stdc++.h>#include <vector>#include <cstdio>#include <cstring>#define sf scanf#define pf printfusing namespace std;cons原创 2016-10-12 14:34:42 · 324 阅读 · 0 评论 -
HDU 1269 迷宫城堡 Tarjan强连通分量
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1269 题意:问当前图是不是强连通的代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 10000 + 50;int top[maxn],id[maxn]原创 2016-10-11 16:08:34 · 353 阅读 · 0 评论 -
HDU 2767 Proving Equivalences Tarjan 强连通缩点
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2767题意:问一个图至少加多少条边后能成为强连通的 我们用Tarjan处理完图的强连通分量以后,就将每一个强连通分量缩成一个点,新的图之后就成为一个有向无环图 让这个有向无环图成为强连通的方法就是加上入度为0的点的个数 和 出度为0的点的个数取max 代码:#include <bits/stdc+原创 2016-10-11 17:03:26 · 291 阅读 · 0 评论 -
HDU 2586 How far away ? Tarjan 离线最近公共祖先
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2586裸的最近公共祖先代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 40000 + 50,maxnm = 200 + 5;int fa[maxn],v原创 2016-10-11 18:49:41 · 325 阅读 · 0 评论 -
HDU 5695 Gym Class 拓扑排序
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5695#include <bits/stdc++.h>#define sf scanf#define pf printftypedef long long LL;using namespace std;const int maxn = 100000 + 5,INF = 2e9;vector<i原创 2016-10-10 14:24:16 · 357 阅读 · 0 评论 -
HDU 4750 最小生成树 kruskal
题目链接题意:代码:#include <cstdio>#include <iostream>#include <queue>#include <iostream>#include <map>#include <vector>#include <algorithm>#include <cstring>#define sf scanf#define pf printfusing na原创 2016-08-07 19:37:35 · 333 阅读 · 7 评论 -
POJ 2492 二分图判断 并查集
POJ - 2492 题意:给出N个BUG 和 M个BUG的性关系 判断是否有同性关系可以用二分图判断来做 也可以用并查集来做 明天补上并查集二分图:如果这N个BUG间只有异性间有关系 那么对这N个BUG做一个关系图 同性之间的BUG之间没有联系 联系建立在不同的性别之间 可以将点集分成两个类别 A B 集合内部没有联系 则这个图为二分图 于是使用二分图判断的常用方法,图染色法 两种颜色将原创 2016-07-27 21:03:30 · 1433 阅读 · 0 评论 -
HDU 5876 Sparse Graph 补图BFS
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5876题意:求补图上起点到所有其它点的最短距离对每一个点,我们只用更新原图不邻接且没有访问过的点既可,复炸度O(m + n) 代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const原创 2016-09-12 20:15:32 · 240 阅读 · 0 评论 -
HDU 4751 二分图判断
题目链接题意: 给一个集合的人和互相之间的关系 问 能不能将这个集合分成两个部分 每个集合之间的人都相互认识判定二分图 染色判定代码:#include <cstdio>#include <iostream>#include <cstring>#define sf scanf#define pf printfusing namespace std;const int maxn = 100原创 2016-08-07 19:44:55 · 385 阅读 · 5 评论 -
POJ 1797 图论 Dijkstra
题目链接题意 求起点到终点 的 一个路径 使路径上最短边最长性质:我们将 满足题意的从起点到点N的路径 记为Path(N) 在Path(N) 上 N 的前一个节点 为pre 那么在Path(N)上从起点到pre的路径 就是 Path(pre ) 否则我们可以将Path(pre)替换这条路径 Path(N)上的最短边只会更长代码:#include原创 2016-08-04 22:56:36 · 258 阅读 · 0 评论 -
HDU 2544 最短路 SPFA
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2544DFS版本 代码:#include <bits/stdc++.h>#define sf scanf#define pf printfusing namespace std;const int maxn = 105,maxm = 10000 + 50;struct Edge{ in原创 2016-10-08 11:47:49 · 355 阅读 · 0 评论