正文
增加 34 行删除 34 行
5 行未改动6789101112131415161718192021222324259 行未改动3536373839404142434 行未改动484950515253545556575859606 行未改动67686970717273747514 行未改动9091929394959697984 行未改动10310410510610710810911011111211 行未改动1241251261271281291301311324 行未改动1371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661675 行未改动17317417517617717817918018110 行未改动1921931941951961971981992003 行未改动20420520620720820921021121221311 行未改动2252262272282292302312322334 行未改动2382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732 行未改动27627727827928028128228328428528628711 行未改动5 行未改动```cpp#include<bits/stdc++.h>using namespace std;using ll = long long;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;}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;}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)d[ver[i]] = d[x] + 1, q.push(ver[i]);}if(d[t] == 0) return Ans;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 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;}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;}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)d[ver[i]] = d[x] + 1, q.push(ver[i]);}if(d[t] == 0) return Ans;Ans += Augment(s, Inf);}}}N;int main() {N.Reset();cin >> Nn;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);}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 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;}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;}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)d[ver[i]] = d[x] + 1, q.push(ver[i]);}if(d[t] == 0) return Ans;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)cin >> Art[i][j], Ans += Art[i][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)cin >> sArt[i][j], Ans += sArt[i][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]);}}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);}}}cout << Ans - N.Dinic();return 0;}```11 行未改动5 行未改动6789101112131415161718192021222324259 行未改动3536373839404142434 行未改动484950515253545556575859606 行未改动67686970717273747514 行未改动9091929394959697984 行未改动10310410510610710810911011111211 行未改动1241251261271281291301311324 行未改动1371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661675 行未改动17317417517617717817918018110 行未改动1921931941951961971981992003 行未改动20420520620720820921021121221311 行未改动2252262272282292302312322334 行未改动2382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732 行未改动27627727827928028128228328428528628711 行未改动5 行未改动```cpp#include<bits/stdc++.h>using namespace std;using ll = long long;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;}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;}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)d[ver[i]] = d[x] + 1, q.push(ver[i]);}if(d[t] == 0) return Ans;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 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;}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;}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)d[ver[i]] = d[x] + 1, q.push(ver[i]);}if(d[t] == 0) return Ans;Ans += Augment(s, Inf);}}}N;int main() {N.Reset();cin >> Nn;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);}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 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;}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;}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)d[ver[i]] = d[x] + 1, q.push(ver[i]);}if(d[t] == 0) return Ans;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)cin >> Art[i][j], Ans += Art[i][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)cin >> sArt[i][j], Ans += sArt[i][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]);}}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);}}}cout << Ans - N.Dinic();return 0;}```11 行未改动