随笔分类 -  算法笔记

摘要:洛谷P1345 假设原来的点编号为i,总共有n个点,那么我们就把每个点拆成两个点,编号分别为i和i+n。其中点i负责连接原图中连入这个点的边,点i+n负责连原图中连出这个点的边。 add ( i, i+n, 1 ) ; add ( i+n, i, 0 ) ; 对于原图中本来就存在的边,它们只是有一个 阅读全文
posted @ 2025-10-09 18:56 xdhking 阅读(14) 评论(0) 推荐(0)
摘要:洛谷p4014 #include<bits/stdc++.h> using namespace std; const int N=120; const int M=N*N+(N<<1); struct edge{int v,c,w,ne;}e[M]; int h[N],id=1; int n,s,t 阅读全文
posted @ 2025-10-09 15:05 xdhking 阅读(29) 评论(0) 推荐(0)
摘要:#include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; #define LL long long #define N 510 #define INF 1e12 int n,m 阅读全文
posted @ 2025-10-08 21:14 xdhking 阅读(18) 评论(0) 推荐(0)
摘要:洛谷P2756 匈牙利算法: #include<bits/stdc++.h> using namespace std; const int N=110; int match[N],vis[N]; int n,m; vector<int> edges[N]; bool dfs(int u){ for( 阅读全文
posted @ 2025-10-07 15:41 xdhking 阅读(16) 评论(0) 推荐(0)
摘要:方法 二分图转换成网络流模型;创建虚拟源点和汇点,将源点连上左边所有点,右边所有点连上汇点,容量皆为1。原来的每条边从左往右连边,容量也皆为1,最大流即最大匹配。 code:洛谷P3386 dinic: #include<bits/stdc++.h> using namespace std; typ 阅读全文
posted @ 2025-10-07 13:04 xdhking 阅读(52) 评论(0) 推荐(0)
摘要:洛谷p5905 #include<bits/stdc++.h> using namespace std; #define endl '\n' typedef long long LL; typedef pair<int,int> PII; const int N=3e3+10,INF=1e9; ve 阅读全文
posted @ 2025-10-06 17:40 xdhking 阅读(14) 评论(0) 推荐(0)
摘要:模板洛谷P4951 #include<iostream> #include<algorithm> #include<vector> using namespace std; const int N=410,M=1e4+10; const double eps=1e-6; typedef long l 阅读全文
posted @ 2025-10-06 00:07 xdhking 阅读(11) 评论(0) 推荐(0)
摘要:洛谷p4782 #include<iostream> #include<vector> #include<algorithm> using namespace std; const int N=2e6+10; int n,m; int dfn[N],low[N],stk[N],instk[N],to 阅读全文
posted @ 2025-10-05 21:20 xdhking 阅读(10) 评论(0) 推荐(0)
摘要:后续补充完善 点双连通分量缩点后建的新图点的数量会增加,如果原图是一条链的话每个点双开个新点,加上割点,总点数要开两倍; 无向基环树用拓扑剥叶子的时候,记得防止剥父亲节点的出度 void topsort(){ queue<int> q; for(int i=1;i<=n;i++){ if(dg[i] 阅读全文
posted @ 2025-10-05 15:54 xdhking 阅读(11) 评论(0) 推荐(0)
摘要:模板题:洛谷p3381 #include<bits/stdc++.h> using namespace std; const int N=5e3+10,M=5e4+10,INF=0x3f3f3f3f; typedef long long LL; int n,m,s,t,id=1; int e[M<< 阅读全文
posted @ 2025-10-03 14:22 xdhking 阅读(8) 评论(0) 推荐(0)
摘要:标准模板 #include<bits/stdc++.h> using namespace std; typedef long long LL; const int N=210,M=5e3+10; int n,m,s,t,d[N],cur[N],vis[N]; int h[N],e[M<<1],ne[ 阅读全文
posted @ 2025-10-02 22:22 xdhking 阅读(16) 评论(0) 推荐(0)