版本比较
上课记录
正文
增加 34 行删除 34 行
5 行未改动6789101011121314151617181920212021222324259 行未改动353637383939404142434 行未改动4849505152525354555656575859606 行未改动6768697071717273747514 行未改动909192939494959697984 行未改动10310410510610710810710810911011111211 行未改动1241251261271281281291301311324 行未改动1371381391401411411421431441451451461471481491501511521521531541551561571581591601601611621631631641651661675 行未改动17317417517617717717817918018110 行未改动1921931941951961961971981992003 行未改动20420520620720820920820921021121221311 行未改动2252262272282292292302312322334 行未改动2382392402412422422432442452462462472482492502512522532542532542552562572562572582592602592602612622632622632642652662672682692692702712722732 行未改动27627727827928028028128228328328428528628711 行未改动5 行未改动```cpp#include<bits/stdc++.h>using namespace std;using ll = long long;constexpr int MAXN = 1e5 + 5; constexpr int MAXN = 1e5 + 5;struct Network { int head[MAXN], Next[MAXN], ver[MAXN], d[MAXN], cur[MAXN]; ll Flow[MAXN]; queue<int> q; int n, m, s, t, tot; void Reset() { for(int i = 2; i <= tot; ++i) Next[i] = ver[i] = Flow[i] = 0; for(int i = 1; i <= n; ++i) head[i] = 0; n = m = s = t = 0; tot = 1; } tot = 1; } void Add(int x, int y, ll z) { ver[++tot] = y, Next[tot] = head[x], head[x] = tot; Flow[tot] = z; }9 行未改动 Flow[i] -= aug, Flow[i ^ 1] += aug; Sum += aug, Min -= aug; if(Min <= 0) break; } return Sum; return Sum; } ll Dinic() { ll Ans = 0; while(1) {4 行未改动 while(!q.empty()) { int x = q.front(); q.pop(); for(int i = head[x]; i; i = Next[i]) if(!d[ver[i]] && Flow[i] != 0) if(!d[ver[i]] && Flow[i] != 0) d[ver[i]] = d[x] + 1, q.push(ver[i]); } if(d[t] == 0) return Ans; Ans += Augment(s, 1000000000000000); Ans += Augment(s, 1000000000000000); } }}N;int main() {6 行未改动 N.Add(u, v, w), N.Add(v, u, 0); } cout << N.Dinic(); return 0;} }```:::## [B-$\mathfrak{Zebraness}$](https://www.luogu.com.cn/problem/AT_abc193_f)最大流不好考虑,我们从最小割角度入手。14 行未改动```cpp#include<bits/stdc++.h>using namespace std;using ll = long long;constexpr int MAXN = 2e5 + 5; constexpr int MAXN = 2e5 + 5;constexpr ll Inf = 1e15;char ch;int Nn, t[105][105];struct Network {4 行未改动 void Reset() { for(int i = 2; i <= tot; ++i) Next[i] = ver[i] = Flow[i] = 0; for(int i = 1; i <= n; ++i) head[i] = 0; n = m = s = t = 0; tot = 1; } tot = 1; } void Add(int x, int y, ll z) { ver[++tot] = y, Next[tot] = head[x], head[x] = tot; Flow[tot] = z; ver[++tot] = x, Next[tot] = head[y], head[y] = tot;11 行未改动 Flow[i] -= aug, Flow[i ^ 1] += aug; Sum += aug, Min -= aug; if(Min <= 0) break; } return Sum; return Sum; } ll Dinic() { ll Ans = 0; while(1) {4 行未改动 while(!q.empty()) { int x = q.front(); q.pop(); for(int i = head[x]; i; i = Next[i]) if(!d[ver[i]] && Flow[i] != 0) if(!d[ver[i]] && Flow[i] != 0) d[ver[i]] = d[x] + 1, q.push(ver[i]); } if(d[t] == 0) return Ans; Ans += Augment(s, Inf); Ans += Augment(s, Inf); } }}N;int main() { N.Reset(); cin >> Nn; N.s = ++N.n, N.t = ++N.n; N.s = ++N.n, N.t = ++N.n; for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= Nn; ++j) { cin >> ch; t[i][j] = ++N.n; if(i != 1) { N.Add(t[i][j], t[i - 1][j], 1); N.Add(t[i - 1][j], t[i][j], 1); } } if(j != 1) { N.Add(t[i][j], t[i][j - 1], 1); N.Add(t[i][j - 1], t[i][j], 1); N.Add(t[i][j - 1], t[i][j], 1); } if(ch == 'B') { if((i + j) & 1) { N.Add(N.s, N.n, Inf), N.Add(N.n, N.t, 0);5 行未改动 N.Add(N.s, N.n, 0), N.Add(N.n, N.t, Inf); } else { N.Add(N.s, N.n, Inf), N.Add(N.n, N.t, 0); } } } } cout << 2 * Nn * (Nn - 1) - N.Dinic(); return 0;}10 行未改动using namespace std;using ll = long long;constexpr int MAXN = 3e5 + 5;constexpr ll Inf = 1000000000000000;ll Art[105][105], Sci[105][105], sArt[105][105], ssci[105][105]; ll Art[105][105], Sci[105][105], sArt[105][105], ssci[105][105];ll Ans = 0, Nn, b[105][105];int fx[5] = {0, 1, 0, -1, 0}, fy[5] = {-1, 0, 1, 0, 0};struct Network { int head[MAXN], Next[MAXN], ver[MAXN], d[MAXN], cur[MAXN];3 行未改动 void Reset() { for(int i = 2; i <= tot; ++i) Next[i] = ver[i] = Flow[i] = 0; for(int i = 1; i <= n; ++i) head[i] = 0; n = m = s = t = 0; tot = 1; } tot = 1; } void Add(int x, int y, ll z) { ver[++tot] = y, Next[tot] = head[x], head[x] = tot; Flow[tot] = z; ver[++tot] = x, Next[tot] = head[y], head[y] = tot;11 行未改动 Flow[i] -= aug, Flow[i ^ 1] += aug; Sum += aug, Min -= aug; if(Min <= 0) break; } return Sum; return Sum; } ll Dinic() { ll Ans = 0; while(1) {4 行未改动 while(!q.empty()) { int x = q.front(); q.pop(); for(int i = head[x]; i; i = Next[i]) if(!d[ver[i]] && Flow[i] != 0) if(!d[ver[i]] && Flow[i] != 0) d[ver[i]] = d[x] + 1, q.push(ver[i]); } if(d[t] == 0) return Ans; Ans += Augment(s, Inf); Ans += Augment(s, Inf); } }}N;int main() { N.Reset(); cin >> Nn >> N.m; for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) cin >> Art[i][j], Ans += Art[i][j]; for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) cin >> Sci[i][j], Ans += Sci[i][j]; for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) cin >> sArt[i][j], Ans += sArt[i][j]; for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) for(int i = 1; i <= Nn; ++i) for(int j = 1; j <= N.m; ++j) cin >> ssci[i][j], Ans += ssci[i][j]; N.s = ++N.n, N.t = ++N.n; for(int i = 1; i <= Nn; ++i) { for(int j = 1; j <= N.m; ++j) { b[i][j] = ++N.n; N.Add(N.s, N.n, Art[i][j]), N.Add(N.n, N.t, Sci[i][j]); N.Add(N.s, N.n, Art[i][j]), N.Add(N.n, N.t, Sci[i][j]); } } for(int i = 1; i <= Nn; ++i) { for(int j = 1; j <= N.m; ++j) {2 行未改动 for(int k = 0; k <= 4; ++k) { int X = i + fx[k], Y = j + fy[k]; if(X < 1 || X > Nn || Y < 1 || Y > N.m) continue; N.Add(N.n - 1, b[X][Y], Inf); N.Add(b[X][Y], N.n, Inf); N.Add(b[X][Y], N.n, Inf); } } } } cout << Ans - N.Dinic(); return 0;}```11 行未改动