原创 拓撲排序
拓撲排序 以入度爲0的做起點 vector<int> top_sort(){ priority_queue<int ,vector<int> ,greater<int > >Q; for(int i=1;i<=n;i++){ if
原创 AC自動機
#include<bits/stdc++.h> using namespace std; const int maxn = 1e7 + 5; const int MAX = 10000000; int cnt; struct node {
原创 BM
#include<bits/stdc++.h> using namespace std; typedef long long ll; typedef unsigned long long ull; #define rep(i,a,n) fo
原创 中國剩餘定理
互質 ll m[N],p[N];//p是質數,m是餘數 ll Exgcd(ll a,ll b,ll &x,ll &y) { if(b==0) { x=1; y=0; retur
原创 逆元
1.exgcd LL Inv(LL a, LL p) { LL x, y, d; d = extgcd(a, p, x, y) if(d == 1) return (x%p+p)%p; return -1;
原创 歐拉函數
euler1int euler(int n) { int res=n,a=n; for(int i=2;i*i<=a;i++) { if(a%i==0) { r
原创 擴展歐幾里得
#include<stdio.h> #include<algorithm> #include<string.h> using namespace std; const int maxm = 100005; int exgcd(int a,
原创 高斯消元
整數#include<cstdio> #include<iostream> #include<algorithm> #include<string> #include<cmath> #include<cstring> using names
原创 tarjan算法
強連通分量 void tarjan(int u){ vis[u]=true; LOW[u]=DFN[u]=cnt++; for(int v:g[u]){ if(!DFN[v]){//沒訪問過繼續 tarjan(v
原创 二分圖-最大匹配
匈牙利算法 struct edge{int u,v;edge *next;}*head[N],e[N]; void add(int u,int v){ edge *p=&e[cnt++]; p->u=u;p->v=v;p->next=he
原创 拓撲排序
拓撲排序 以入度爲0的做起點 vector<int> top_sort(){ priority_queue<int ,vector<int> ,greater<int > >Q; for(int i=1;i<=n;i++){ if
原创 鄰接鏈表
鄰接鏈表 struct edge{int u,v;edge *next;}*head[N],e[N]; head[N]->0 top->0 void add(int u,int v){ edge *p=&e[top++]; p->u=u;
原创 歐拉函數
euler1int euler(int n) { int res=n,a=n; for(int i=2;i*i<=a;i++) { if(a%i==0) { r
原创 最短路
Floyd for(int k=1;k<=n;k++) for(int i=1;i<=n;i++) for(int j=1;j<=n;j++) dp[i][j]=min(dp[i][j],dp[i][k]+dp[k][j]); Dijks
原创 並查集
int find(int x){return x==F[x]?x:find(F[x]);} void join(int x,int y){ int fx=find(x); int fy=find(y); if(fx!