代码模板。
巨长的代码模板。
图论
图
连通块的划分(图的染色)
1 | void dfs(int x) { |
BFS遍历一个树/图
1 | void bfs() { |
Dijkstra
1 | void Dijkstra(int x) { |
Floyed
1 | void Floyed() { |
Kruskal
1 | void Kruskal() { |
并查集
1 | void init() { |
拓扑排序
1 | void Topsort() { |
二分图最大匹配
1 | bool find(int x) { |
Tarjan求强联通分量
1 | void Tarjan(int x) { |
缩点
1 | void Tarjan() { |
树
LCA
树上倍增
1 | void bfs() { |
Tarjan算法离线求LCA
1 | void init() { |
树的直径
1 | void dp(int x) { |
树的重心
1 | void dfs(int x) {//树的重心的定义就是将该点删去之后所形成的最大的子树最小的那个点 |
树的各点子树的大小
1 | void dfs(int x) { |
树的各点的深度
1 | void dfs(int x) { |
数论
Gcd 和 Lcm
1 | int gcd(int a, int b) { |
线性筛求素数
1 | ll prime[maxn], size = 0; |
EXGCD
1 | void Exgcd(int a, int b, int& d, int& x, int& y) { |
求逆元
1 | //如果p是素数那么可以使用小费马定理 |
快速幂
1 | int power(int a, int b, int p) { |
龟速乘
1 | ll Mul(ll a, ll b, ll p) { |
组合数学
1 | void init() { |
矩阵乘法
1 | struct Mat { |
数据结构
链表
1 | inline void init() { |
队列
1 | //STL |
优先队列
1 | //STL |
栈
1 | stack<int> s; |
单调队列
1 |
单调栈
1 |
Hash表
1 | unsigned long long h(char s[]) { |
KMP
1 | void prekmp() { |
树状数组
1 | inline void add(int x, int v) { |
线段树
1 | struct Segment { |
分块
1 | void build() { |
搜索
Dfs
1 | void dfs(int x) { |
Bfs
1 | void bfs(int x) { |
迭代加深
1 |
其他
二分
1 | //求小于等于x最大的那一个 |