
图论模板
maze_illusion
这个作者很懒,什么都没留下…
展开
-
朱刘算法(最小树形图)
复杂度O(n*m)struct edge{ int u,v,cost;}es[maxm];int pre[maxn],id[maxn],vis[maxn],in[maxn],n,m;int ZhuLiu( int root ){ int res = 0; while ( true ) { for ( int i=0 ; i<n ...原创 2018-09-04 13:20:32 · 384 阅读 · 0 评论 -
2-SAT(染色法,求字典序最小解)
int tol,head[maxn];struct edge{ int to,next;}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; head[u] = tol++;}bool vis[maxn]; int S[maxn],top;b...原创 2018-09-05 19:40:13 · 710 阅读 · 0 评论 -
边双连通分支模板
int tol,head[maxn];struct edge{ int to,next; bool cut;}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; es[tol].cut = false; head[u] = tol+...原创 2018-09-03 14:55:07 · 316 阅读 · 0 评论 -
染色判断二分图
bool ok[maxn]; int color[maxn];//ok表示点是否存在图中,color表示点的颜色 bool dfs( int u , int col ){ color[u] = col; for( int i=head[u] ; i!=-1 ; i=es[i].next ) { int v = es[i].to; if...原创 2018-09-03 16:25:23 · 364 阅读 · 0 评论 -
点双连通分支(按边分块)
int tol,head[maxn];struct edge{ int to,id,next;}es[maxm];void addedge( int u , int v , int d ){ es[tol].to = v; es[tol].id = d; es[tol].next = head[u]; head[u] = tol++;}int...原创 2018-09-03 20:54:45 · 259 阅读 · 0 评论 -
点双连通分支(按点分块)
int tol,head[maxn];struct edge{ int to,next;}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; head[u] = tol++;}int Low[maxn],Dfn[maxn],Stack[maxn...原创 2018-09-03 21:03:47 · 348 阅读 · 1 评论 -
2-SAT(强连通缩点,拓扑排序求任意解)
int tol,head[maxn];int dol,dead[maxn];struct edge{ int to,next;}es[maxm],dag[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; head[u] = tol++;}void...原创 2018-09-06 12:28:10 · 512 阅读 · 0 评论 -
曼哈顿最小生成树
struct point{ int x,y,id; friend bool operator<( const point&a ,const point&b ) { if ( a.x!=b.x ) return a.x<b.x; else return a.y<b.y; }}p[maxn];in...原创 2018-09-06 13:35:41 · 280 阅读 · 0 评论 -
一般图匹配(带花树)
int tol,head[maxn];struct edge{ int u,v,next;}es[maxm];void addedge( int u , int v ){ es[tol].u = u; es[tol].v = v; es[tol].next = head[u]; head[u] = tol++;}int n,m,f[maxn]...原创 2018-09-06 21:29:30 · 483 阅读 · 0 评论 -
一般图最大权匹配(带花树)
#include<map>#include<set>#include<ctime>#include<stack>#include<cmath>#include<queue>#include<vector>#include<string>#include<c原创 2018-09-07 16:08:09 · 2657 阅读 · 1 评论 -
割点和桥模板
int tol,head[maxn];struct edge{ int to,next; bool cut;//是否为割边}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; es[tol].cut = false; head[u]...原创 2018-09-03 14:03:57 · 247 阅读 · 0 评论 -
zkw费用流
int tol,head[maxn];struct edge{ int to,next,cap,flow,cost;}es[maxm];void addedge( int u , int v , int cap , int cost ){ es[tol].to = v; es[tol].cap = cap; es[tol].cost = cost; ...原创 2018-09-05 17:46:41 · 470 阅读 · 0 评论 -
二分匹配(匈牙利算法)
int tol,head[maxn];struct edge{ int to,next;}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; head[u] = tol++;}int linker[maxn],un; bool used[max...原创 2018-09-04 15:13:13 · 129 阅读 · 0 评论 -
二分匹配(Hopcroft-Carp算法)
int tol,head[maxn];struct edge{ int to,next;}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; head[u] = tol++;}int un,dis;int mx[maxn],my[maxn];...原创 2018-09-04 19:08:46 · 279 阅读 · 0 评论 -
生成树计数模板(求行列式)
Matrix-Tree定理(Kirchhoff矩阵-树定理)G的度数矩阵D[G]是一个n*n的矩阵,并且满足:当i≠j时,D[i][j]=0;当i=j时,D[i][j]等于vi的度数 G的邻接矩阵A[G]是一个n*n的矩阵,并且满足:如果vi,vj之间有边直接相连,则A[i][j]=1,否则为0 G的Kirchhoff矩阵C[G]为C[G]=D[G]-A[G],则Matrix-Tree定理...原创 2018-09-04 21:43:42 · 317 阅读 · 0 评论 -
次小生成树模板
算法思路:求最小生成树,用maxx[i][j]来表示最小生成树中i到j的最大边权,求完后,直接枚举所有不在最小生成树中的边,替换最大边权的边,更新答案bool vis[maxn],used[maxn][maxn];int n,dis[maxn],pre[maxn],maxx[maxn][maxn],cost[maxn][maxn];int Prim(){ int ans=inf...原创 2018-09-02 14:39:43 · 127 阅读 · 0 评论 -
有向图强连通分量模板
int tol,head[maxn];struct edge{ int to,next;}es[maxm];void addedge( int u , int v ){ es[tol].to = v; es[tol].next = head[u]; head[u] = tol++;}int Low[maxn],Dfn[maxn],Stack[maxn...原创 2018-09-02 18:50:12 · 179 阅读 · 0 评论 -
二分图最大权匹配
int un,vn;//un左边点数,vn右边点数int g[maxn][maxn];int linker[maxn],lu[maxn],lv[maxn];int slack[maxn];bool visu[maxn],visv[maxn];bool dfs( int u ){ visu[u] = true; for ( int v=0 ; v<vn ; v++...原创 2018-09-05 12:54:00 · 134 阅读 · 0 评论 -
二分图多重匹配
int un,vn;int g[maxn][maxn];int linker[maxn][maxn];bool used[maxn];int num[maxn];//右边最大匹配数bool dfs( int u ){ for ( int v=0 ; v<vn ; v++ ) if ( g[u][v]&&!used[v] ) ...原创 2018-09-05 13:29:36 · 266 阅读 · 0 评论 -
最大流模板
int tol,head[maxn];struct edge{ int to,next,cap,flow;}es[maxm];void addedge( int u , int v , int w ){ es[tol].to = v; es[tol].cap = w; es[tol].flow = 0; es[tol].next = head[u...原创 2018-09-05 14:32:47 · 171 阅读 · 0 评论 -
最小费用最大流模板
int tol,head[maxn];struct edge{ int to,next,cap,flow,cost;}es[maxm];void addedge( int u , int v , int cap , int cost ){ es[tol].to = v; es[tol].cap = cap; es[tol].cost = cost; ...原创 2018-08-22 21:09:02 · 210 阅读 · 0 评论 -
dijkstra优化的最小费用最大流
const int inf = 0x3f3f3f3f;int tol,head[4010];struct edge{ int to,next,cap,flow,cost;}es[8000010];void init(){ tol = 0; memset( head , -1 , sizeof(head) );}void addedge( int u , int v ,...原创 2019-07-30 16:33:52 · 599 阅读 · 0 评论