图论
clay_2791
不愿随波逐流,迟早掀风起浪
展开
-
树状数组
树状数组1:#include <iostream>#define lowbit(x) x&-xusing namespace std;const int maxn = 500005;int C[maxn],u,v,z,n,m;void update(int x,int y){ for(int i = x ; i <= n ; i +=lowbit(i))C...原创 2019-08-08 15:21:13 · 65 阅读 · 0 评论 -
RMQ
luoguST表题#include <iostream>#include <algorithm>#include <cmath>#include <cstdio>using namespace std;const int maxn =100010;long long dp[maxn][20],n,m;void init(int n)...原创 2019-08-08 19:39:07 · 167 阅读 · 0 评论 -
求LCA三大模板
luogu3379为例1、倍增算法(第三快#include <cstdio>#include <algorithm>#define maxn 500005using namespace std;struct node{ int to,next;}E[maxn*2];int n,N,m,root,tot,lg[maxn],head[maxn],to[max...原创 2019-08-05 23:01:51 · 102 阅读 · 0 评论 -
最小生成树模板Prim与Kruskal
Kruskal算法int fa[maxn];struct edge{ int u,v,w;}E[maxn];bool cmp(const edge &a,const edge &b){ return a.w<b.w;}void merge(){fa[find(u)]=find(v);}int find(){return fa[u]==u?u:fa[u]=...原创 2019-08-02 21:21:35 · 111 阅读 · 0 评论 -
luoguP3372模板
线段树模板luogu P3372#include <iostream>using namespace std;const int maxn = 100010;int a[maxn+2],n,m;struct tree{ int l,r; long long add,pre;}t[maxn*4+2];void build(int p,int l,int r)//建树...原创 2019-07-28 15:06:43 · 113 阅读 · 0 评论 -
最短路+差分约束
Floyd#include <cstdio>#include <algorithm> #define int long longusing namespace std; const int inf = 2147483647;int mp[10000][10000],n,m,root;inline int read(){ int x=0; bo...原创 2019-08-27 19:20:31 · 121 阅读 · 0 评论