随笔分类 - 图论 / 图论板子
摘要:最大流 题目要求:给出n点 m边 src sink 然后每条边有 u v capacity 求最大流 题目链接P3376 【模板】网络最大流 EK(Edmonds–Karp)算法: \[\begin{align} & \color{Red}时间复杂度O(nm^2) \ & \color{Red}空
阅读全文
摘要:最短路 弗洛伊德:全源最短路: #include <cstdio> #include <algorithm> #include <iostream> #include <c
阅读全文
摘要:2-Sat \[\begin{align*} &\LARGE\color{Red}大意:\ &有n个数a_i,m个约束条件都需要满足\ &条件形如(i,a,j,b) \quad a_i=a \ \text{or} \ a_j=b\\\ &\LARGE\color{Red}思路:\ &让a
阅读全文
摘要:P3388 【模板】割点 Note:图可能不联通,因此每次tarjan都要更新root #include <cstdio> #include <stack> #include <cmath> #include <algorithm> #include <iostream> #include <cst
阅读全文
摘要:两种算法Prim and Kruskal Prim: 使用链式前项星 从根节点root开始加点直到加完所有点 dist[u] 表示从已经包含在 MST 中的节点到节点 u 的最小边权值 #include <cstdio> #include <queue> #include <deque> #incl
阅读全文
摘要: 做法:Tarjan 记录scc 然后根据SCC去重新建图 #include <cstdio> #include <stack> #include <algorithm> #include <iostream> #include <cstr
阅读全文
摘要:LCA最近公共祖先 给出一个表格 最近公共祖先 朴素算法 倍增算法 Tarjan算法 树链剖分 数据结构 fa[u],de
阅读全文
摘要:
树的直径 给定n个点 n-1条边 和每条边的val 输出直径的大小和 直径上的点的序号 input: 8 1 2 2 1 3 1 1 5 10 2 4 3 4 6 4 3 7 5 7 8 2 output: 19 6 4 2 1 5 法1.DFS 思路:跑两遍dfs 第一次求出一个端点c1,第二次求
阅读全文

摘要:介绍5种存图的方法 1.邻接矩阵 const int N =1e3+9; int G[N][N];//G[i][j]即val(i->j) void dfs(int u){ vis[u] = 1; for(int v=1 ; v<=n ; ++v){ if(G[u][v]!=0){ printf("%
阅读全文