#include <bits/stdc++.h>
using namespace std;
using namespace chrono;
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
auto st = high_resolution_clock::now();
// 代码
auto ed = high_resolution_clock::now();
auto ms = duration_cast<milliseconds>(ed - st);
cout << "Time: " << ms.count() << " ms\n";
return 0;
}一些好文
tirck
https://www.cnblogs.com/wyb-sen/p/17234499.html
https://www.cnblogs.com/lsj2009/p/17668670.html
https://www.luogu.me/article/o0yp5tx3
https://www.luogu.me/article/fzxdw3x2
https://www.luogu.com.cn/article/krybn2f5
https://www.luogu.com.cn/article/cqhi72t6
Accepted
AC AC AC AC AC AC AC AC AC AC AC AC AC
AC 省一 金牌 AK
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
orz orz orz %%%
2025年8月15日 AC200题
2025年9月20日 首次参加 (初赛):77.5
2025年9月20日 首次参加 (初赛):62.5
2025年9月22日 首次AC紫题
OI生涯第一年 {
红题:73
橙题:64
黄题:58
绿题:42
蓝题:16
紫题:4
黑题:0
等级分(最大):919
}
2025年11月1日 首次参加 (复赛):260
2025年11月1日 首次参加 (复赛):80
2025年11月25日 洛谷等级分破1000
2025年12月16日 洛谷获得红名
2025年12月29日 首次AC黑题
2026年1月29日 紫题AC20
2026年2月4日 AC400题
2026年3月17日 绿题AC100
2026年3月18日 蓝题AC100
2026年5月6日 AC500题
2026年5月9日 打卡400天
2026年7月30日 AC600题
2026年8月21日 打卡500天
2026年9月19日 第二次参加 (初赛):71
2026年10月31日 第二次参加 (复赛):168
网络流:
性质(割):
f(S, T)表示从S集流向T集的流量
1.f(X, Y) = -f(Y, X)
2.f(X, X) = 0
3.f(Z, X∪Y) = f(Z, X) + f(Z, Y) (X∩Y = ∅)
4.f(X∪Y, Z) = f(X, Z) + f(Y, Z) (X∩Y = ∅)
定理:
表示流网络的任何一个割
表示流网络的任何一个可行流
表示从集到集的容量
最大流 <= 最小割
最大流最小割定理(三个定理均可互相到达)
1.f是最大流
2.G_f中不存在增广路径(G_f是一个残留网络)
3.存在[S, T], |f| = c(S, T)
最大流模板
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 50010, M = 300010;
const ll INF = 1e18;
ll f[M], mf;
int h[N], ver[M], ne[M], d[N], now[M], n, m, s, t, tot;
queue<int> q;
void add(int x, int y, int z) {
ver[++tot] = y, f[tot] = z, ne[tot] = h[x], h[x] = tot;
ver[++tot] = x, f[tot] = 0, ne[tot] = h[y], h[y] = tot;
}
bool bfs() {
memset(d, 0, sizeof d);
while (q.size()) q.pop();
q.push(s);
d[s] = 1;
now[s] = h[s];
while (q.size()) {
int x = q.front();
q.pop();
for (int i = h[x]; i; i = ne[i]) {
if (f[i] && !d[ver[i]]) {
q.push(ver[i]);
now[ver[i]] = h[ver[i]];
d[ver[i]] = d[x] + 1;
if (ver[i] == t) return 1;
}
}
}
return 0;
}
ll dinic(int x, ll flow) {
if (x == t) return flow;
ll res = 0;
for (int i = now[x]; i && res < flow; i = ne[i]) {
now[x] = i;
if (f[i] && d[ver[i]] == d[x] + 1) {
ll k = dinic(ver[i], min(flow - res, f[i]));
if (!k) d[ver[i]] = 0;
f[i] -= k, f[i ^ 1] += k, res += k;
}
}
return res;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(nullptr);
cin >> n >> m >> s >> t;
tot = 1;
for (int i = 1; i <= m; i++) {
int x, y, z;
cin >> x >> y >> z;
add(x, y, z);
}
ll flow = 0;
while (bfs()) {
while (flow = dinic(s, INF)) mf += flow;
}
cout << mf;
return 0;
}