图论
护理系程序猿
这个作者很懒,什么都没留下…
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
网络流总结
网络流原创 2022-08-08 11:08:13 · 189 阅读 · 0 评论 -
SPFA优化(SLF+LLL)
SPFA优化(SLF+LLL)转载 2022-07-30 11:54:56 · 153 阅读 · 0 评论 -
求树的直径
两遍dfs #include<cstdio> #include<cstring> #include<algorithm> using namespace std; const int N=100005; int n,m,t,p,ans; int d[N],first[N],v[N],w[N],next[N]; void add(int x,int y,int z) { t++; next[t]=first[x]; first[x]=t; v[t]=y; w[t]转载 2022-04-10 18:32:43 · 101 阅读 · 0 评论 -
拓扑图判环
拓扑图判环 使用拓扑排序判断无向图和有向图中是否存在环的区别在于: 在判断无向图中是否存在环时,是将所有度 <= 1 的结点入队; 在判断有向图中是否存在环时,是将所有入度 = 0 的结点入队。 ...原创 2022-03-19 15:27:58 · 323 阅读 · 0 评论 -
LCA(倍增,Tarjan)
LCA倍增tarjan 倍增 #include<bits/stdc++.h> //#define max(a,b) (((a) > (b)) ? (a) : (b)) using namespace std; int n,T,root,deep[500010],maxdeep,f[500010][25]; int tot,h[500010],top; struct node{ int next,to; }e[2*500010]; void add(int u,int v) { ++to原创 2022-01-22 23:49:22 · 310 阅读 · 0 评论 -
最小生成树
最小生成树 prim #include<bits/stdc++.h> #define inf 1000000000 using namespace std; int n,m,dis[5010],ans; bool b[5010]; int tot,h[5010],nxt[400010],to[400010],cost[400010]; void add(int x,int y,int z) { ++tot; nxt[tot]=h[x]; h[x]=tot; to[tot]=y; cos原创 2022-01-22 17:17:52 · 339 阅读 · 0 评论 -
并查集..
1.核心思想:建立一个具有连通性质的集合 2. 实现关键:路径压缩 3.初始化:自己的父亲是自己 4. 代码 #include<bits/stdc++.h> using namespace std; const int nu=500100; struct node{ int u,v,w; }e[nu]; int f[nu],p,m,dis,k=0; int getf(int x) { if(x==f[x])return x; else return f[x]=getf(f原创 2022-01-22 16:32:33 · 346 阅读 · 0 评论 -
最短路(3算法)
最短路floyeddijkstraSPFA floyed 核心代码 for (i = 1; i <= n; i++){ for (j = 1; j <= n; j++){ if (e[i][j] > e[i][1] + e[1][j]) e[i][j] = e[i][1] + e[1][j]; } } dijkstra 不能有负权边 堆优化,复杂度O(nlogn) 代码 #include<bits/stdc++.h&g原创 2022-01-22 12:03:45 · 294 阅读 · 0 评论 -
拓扑排序DAG
拓扑排序 适用:有向无环图 使用情景:每个项目有自己的前置任务 复杂度O{N+E} 代码(noip神经网络) #include<queue> #include<cstdio> #include<algorithm> #define N 101 using namespace std; struct edge{ int to,val,nxt; } e[N*N]; struct answer{ int id,val; } ans[N]; int h,i,m,n,t,u原创 2022-01-22 10:44:16 · 226 阅读 · 0 评论
分享