版本比较
模板库
正文
增加 82 行删除 82 行
112334556789910111112131314151516171718191920212122232324252526272728292930313132333334353536373738393940414142434344454546474748494950515152535455555657575859596061626354 行未改动11811912012112212212312412412512612712859 行未改动18818919019119219219319419419519619719824 行未改动223224225226227227228229230231199 行未改动全部展开431432433434435435436437437438439440441121 行未改动全部展开56356456556656756756856957057145 行未改动61761861962062162162262362362462562662769 行未改动6976986997007017017027037047057067077087097107107117127137137147157167173 行未改动72172272372472572572672772772872973073139 行未改动77177277377477577577677777877952 行未改动832833834835836836837838839840125 行未改动全部展开96696796896997097097197297297397497497597697797869 行未改动104810491050105110521052105310541055105635 行未改动109210931094109510961096109710981099110011011101110211031103110411051106110774 行未改动11821183118411851186118611871188118911901191119211931193119411951195119611971198119920 行未改动122012211222122312241224122512261227122845 行未改动127412751276127712781278127912801280128112821283128433 行未改动131813191320132113221322132313241325132611 行未改动1338133913401341134213421343134413451346134713481348134913501351135270 行未改动142314241425142614271427142814291430143176 行未改动150815091510151115121512151315141514151515161516151715181518151915201520152115221523152453 行未改动157815791580158115821582158315841585158615871588158915891590159115911592159315941595112 行未改动全部展开170817091710171117121712171317141715171633 行未改动175017511752175317541754175517561756175717581758175917601760176117621763176436 行未改动18011802180318041805180518061807180818099 行未改动181918201821182218231823182418251825182618271828182940 行未改动187018711872187318741874187518761876187718781879188082 行未改动196319641965196619671967196819691969197019711972197357 行未改动用于考前练习板子。 用于考前练习板子。
### 零. 目录 ### 零. 目录
已经完成了的: 已经完成了的:
- **图论**
树的直径 树的直径
树的重心 树的重心
最近公共祖先 $Lca$(倍增,$Tarjan$,树剖) 最近公共祖先 $Lca$(倍增,$Tarjan$,树剖)
重链剖分 重链剖分
树上启发式合并 $Dsu\ on\ tree$ 树上启发式合并 $Dsu\ on\ tree$
树哈希 树哈希
最小生成树($Kruskal,Prim,Kruskal$ 重构树) 最小生成树($Kruskal,Prim,Kruskal$ 重构树)
最短路($dijkstra,Floyd$)($spfa$ 容易被卡,只用于判负环,差分约束会用到) 最短路($dijkstra,Floyd$)($spfa$ 容易被卡,只用于判负环,差分约束会用到)
差分约束系统 差分约束系统
同余最短路(待补充) 同余最短路(待补充)
$Tarjan$ 求强连通分量 $Tarjan$ 求强连通分量
$Tarjan$ 求割点 $Tarjan$ 求割点
$Tarjan$ 求点双联通分量 $Tarjan$ 求点双联通分量
$Tarjan$ 求边双连通分量 $Tarjan$ 求边双连通分量
广义圆方树 广义圆方树
欧拉图,欧拉回路,欧拉路径 欧拉图,欧拉回路,欧拉路径
二分图最大匹配(匈牙利,$Dinic$) 二分图最大匹配(匈牙利,$Dinic$)
- **字符串算法** - **字符串算法**
$Manacher$ $Manacher$
$kmp$ $kmp$
失配树 失配树
$exkmp$ $exkmp$
***
### 一. 图论 ### 一. 图论
#### 树的直径 #### 树的直径
[here](https://www.luogu.com.cn/problem/SP1437) [here](https://www.luogu.com.cn/problem/SP1437)
```cpp/*知识点:树的直径*/#include <iostream>54 行未改动 return 0;}```
#### 树的重心 #### 树的重心
[here](https://vjudge.csgrandeur.cn/contest/556202#problem/A) [here](https://vjudge.csgrandeur.cn/contest/556202#problem/A)
```cpp/*知识点:树的重心*/#include <iostream>59 行未改动 return 0;}```
#### 最近公共祖先 $Lca$ #### 最近公共祖先 $Lca$
[here](https://www.luogu.com.cn/problem/P3379) [here](https://www.luogu.com.cn/problem/P3379)
```cpp/*知识点:倍增lca*/#include <iostream>24 行未改动int fa[maxn][20],deep[maxn];inline void dfs(int u,int Fa){ deep[u] = deep[Fa] + 1; fa[u][0] = Fa; for(int i=1;i<=18;i++) for(int i=1;i<=18;i++) fa[u][i] = fa[fa[u][i - 1]][i - 1]; for(int i=head[u];i;i=e[i].next){ int v = e[i].to; if(v == Fa) continue;199 行未改动全部展开 return 0;}```
#### 重链剖分 #### 重链剖分
[here](https://www.luogu.com.cn/problem/P3384) [here](https://www.luogu.com.cn/problem/P3384)
```cpp/*知识点:重链剖分*/#include <iostream>121 行未改动全部展开 while(top[u] != top[v]){ if(deep[top[u]] < deep[top[v]]) swap(u,v); seg.update(1,1,n,dfn[top[u]],dfn[u],x); u = fa[top[u]]; } } if(deep[u] < deep[v]) swap(u,v); seg.update(1,1,n,dfn[v],dfn[u],x);}inline ll query(int u,int v){45 行未改动 return 0;}```
#### 树上启发式合并 $Dsu\ on\ tree$ #### 树上启发式合并 $Dsu\ on\ tree$
[here](https://www.luogu.com.cn/problem/U41492) [here](https://www.luogu.com.cn/problem/U41492)
```cpp/*知识点:Dsu on tree*/#include <iostream>69 行未改动 for(int i=dfn[u];i<=dfn[u]+sz[u]-1;i++) Delete(point[i]);}int main(){
read(n); for(int i=1;i<n;i++){ int u,v; read(u,v); add(u,v); add(v,u); } for(int i=1;i<=n;i++) read(color[i]);
dfs1(1,1); dfs2(1,1,1);
read(q); while(q--){ int u; read(u);3 行未改动 return 0;}```
#### 树哈希 #### 树哈希
[here](https://www.luogu.com.cn/problem/P5043) [here](https://www.luogu.com.cn/problem/P5043)
```cpp/*知识点:树哈希*/#include <iostream>39 行未改动 dp[u] = max(dp[u],n - sz[u]); if(dp[u] <= n / 2){ if(!root[id][0]) root[id][0] = u; else root[id][1] = u; } }}ull Hash[maxn][maxn];ull RealHash[maxn];const ull mask = chrono::steady_clock::now().time_since_epoch().count();52 行未改动 return 0;}```
#### 最小生成树 #### 最小生成树
```cpp/*知识点:kruskal最小生成树*/#include <iostream>125 行未改动全部展开 return 0;}```
还有 $Kruskal$ 重构树,[看这道题](https://www.luogu.com.cn/problem/P4768)。 还有 $Kruskal$ 重构树,[看这道题](https://www.luogu.com.cn/problem/P4768)。
#### 最短路 #### 最短路
$dijkstra:$ [Here](https://www.luogu.com.cn/problem/P4779) $dijkstra:$ [Here](https://www.luogu.com.cn/problem/P4779)
```cpp/*知识点:dijkstra*/#include <iostream>69 行未改动 return 0;}```
$Floyd:$ [Here](https://www.luogu.com.cn/problem/B3647) $Floyd:$ [Here](https://www.luogu.com.cn/problem/B3647)
```cpp/*知识点:Floyd*/#include <iostream>35 行未改动 for(int j=1;j<=n;j++) printf("%d ",dis[i][j]); printf("\n"); }
return 0;}```
#### 差分约束系统 #### 差分约束系统
[here](https://www.luogu.com.cn/problem/P1993) [here](https://www.luogu.com.cn/problem/P1993)
```cpp/*知识点:差分约束系统*/#include <iostream>74 行未改动 add(a,b,0); add(b,a,0); } } for(int i=1;i<=n;i++) add(0,i,0); //别忘了要建立超级源点防止不连通。 for(int i=1;i<=n;i++) add(0,i,0); //别忘了要建立超级源点防止不连通。 spfa(0);
return 0;}```
#### $Tarjan$ 求强连通分量 #### $Tarjan$ 求强连通分量
[here](https://www.luogu.com.cn/problem/B3609) [here](https://www.luogu.com.cn/problem/B3609)
```cpp/*知识点:Tarjan 求强连通分量*/#include <iostream>20 行未改动inline void add(int u,int v){ e[++cnt].to = v; e[cnt].next = head[u]; head[u] = cnt;} }int dfn[maxn],low[maxn],color[maxn],sta[maxn];int Time,scccnt,top;bool in_sta[maxn];vector<int>scc[maxn];45 行未改动 return 0;}```
#### $Tarjan$ 求割点 #### $Tarjan$ 求割点
[here](https://www.luogu.com.cn/problem/P3388) [here](https://www.luogu.com.cn/problem/P3388)
```cpp/*知识点:Tarjan 求割点*/#include <iostream>33 行未改动 if(!dfn[v]){ Tarjan(v,root); if(u == root) son++; low[u] = min(low[u],low[v]); if(low[v] >= dfn[u] && u != root) cut[u] = 1; if(low[v] >= dfn[u] && u != root) cut[u] = 1; } else low[u] = min(low[u],dfn[v]); } if(u == root && son >= 2) cut[u] = 1; //特殊处理根节点11 行未改动 if(!dfn[i]) Tarjan(i,i); for(int i=1;i<=n;i++) if(cut[i]) tot++; printf("%d\n",tot); for(int i=1;i<=n;i++) if(cut[i]) printf("%d ",i); if(cut[i]) printf("%d ",i);
return 0;}```
#### $Tarjan$ 求点双联通分量 #### $Tarjan$ 求点双联通分量
```cpp/*知识点:Tarjan求点双*/#include <iostream>70 行未改动 return 0;}```
#### $Tarjan$ 求双连通分量 #### $Tarjan$ 求双连通分量
```cpp/*知识点:Tarjan 求边双*/#include <iostream>76 行未改动
return 0;}```可以用于缩点得到边双树。 可以用于缩点得到边双树。
#### 广义圆方树 #### 广义圆方树
直接看这道题:[load压力](http://222.180.160.110:1024/contest/4027/problem/6)。 直接看这道题:[load压力](http://222.180.160.110:1024/contest/4027/problem/6)。
#### 欧拉图,欧拉回路,欧拉路径 #### 欧拉图,欧拉回路,欧拉路径
[here](https://www.luogu.com.cn/problem/P7771) [here](https://www.luogu.com.cn/problem/P7771)
```cpp/*知识点:Hierholzer法求欧拉回路/欧拉路径*/#include <iostream>53 行未改动 if(out[i] - in[i] == 1) S = i; } for(int i=1;i<=n;i++) sort(G[i].begin(),G[i].end()); if(!S) S = 1; //可能存在欧拉回路,导致所有的in=out,此时贪心将起点设为1即可 dfs(S); dfs(S); for(int i=top;i>=1;i--) printf("%d ",sta[i]);
return 0;}```
#### 二分图最大匹配(匈牙利,$Dinic$) #### 二分图最大匹配(匈牙利,$Dinic$)
[here](https://www.luogu.com.cn/problem/P3386) [here](https://www.luogu.com.cn/problem/P3386)
```cpp/*知识点:匈牙利算法求二分图最大匹配*/#include <iostream>112 行未改动全部展开inline int dfs(int u,int flow){ if(u == T) return flow; int rest = flow; for(int i=cur[u];i&&rest;i=e[i].next){ cur[u] = i; cur[u] = i; int v = e[i].to,w = e[i].w; if(deep[v] == deep[u] + 1 && w){ int sum = dfs(v,min(rest,w)); if(!sum) deep[v] = 0;33 行未改动 return 0;}```
*** ***
### 二. 字符串算法 ### 二. 字符串算法
#### $Manacher$ #### $Manacher$
[here](https://www.luogu.com.cn/problem/P3805) [here](https://www.luogu.com.cn/problem/P3805)
```cpp/*知识点:Manacher*/#include <iostream>36 行未改动 else{ r[i] = pos + r[pos] - i; while(i + r[i] <= len && i - r[i] >= 1 && s[i + r[i]] == s[i - r[i]]) r[i]++; r[i]--; } } if(i + r[i] > R) R = i + r[i],pos = i; } }}9 行未改动 return 0;}```
#### $kmp$ #### $kmp$
[here](https://www.luogu.com.cn/problem/P3375) [here](https://www.luogu.com.cn/problem/P3375)
```/*知识点:kmp*/#include <iostream>40 行未改动 return 0;}```
#### 失配树($Fail$ 树) #### 失配树($Fail$ 树)
[here](https://www.luogu.com.cn/problem/P5829) [here](https://www.luogu.com.cn/problem/P5829)
```cpp/*知识点:kmp,失配树*/#include <iostream>82 行未改动 return 0;}```
#### $exkmp$ #### $exkmp$
[here](https://www.luogu.com.cn/problem/P5410) [here](https://www.luogu.com.cn/problem/P5410)
```cpp/*知识点:exkmp*/#include <iostream>57 行未改动