From 09f0a2be59d977ad9c6d158df5ea9afed9dbce7f Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Thu, 9 Feb 2023 16:50:22 +0800 Subject: [PATCH] =?UTF-8?q?#2239.=20=E3=80=8CCQOI2014=E3=80=8D=E5=8D=B1?= =?UTF-8?q?=E6=A1=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1697765 --- LibreOJ/2239/2239.cpp | 147 +++++++++++++++++++++++++++++++++ LibreOJ/2239/data/bridge1.in | 3 + LibreOJ/2239/data/bridge1.out | 3 + LibreOJ/2239/data/bridge10.in | 3 + LibreOJ/2239/data/bridge10.out | 3 + LibreOJ/2239/data/bridge2.in | 3 + LibreOJ/2239/data/bridge2.out | 3 + LibreOJ/2239/data/bridge3.in | 3 + LibreOJ/2239/data/bridge3.out | 3 + LibreOJ/2239/data/bridge4.in | 3 + LibreOJ/2239/data/bridge4.out | 3 + LibreOJ/2239/data/bridge5.in | 3 + LibreOJ/2239/data/bridge5.out | 3 + LibreOJ/2239/data/bridge6.in | 3 + LibreOJ/2239/data/bridge6.out | 3 + LibreOJ/2239/data/bridge7.in | 3 + LibreOJ/2239/data/bridge7.out | 3 + LibreOJ/2239/data/bridge8.in | 3 + LibreOJ/2239/data/bridge8.out | 3 + LibreOJ/2239/data/bridge9.in | 3 + LibreOJ/2239/data/bridge9.out | 3 + 21 files changed, 207 insertions(+) create mode 100644 LibreOJ/2239/2239.cpp create mode 100644 LibreOJ/2239/data/bridge1.in create mode 100644 LibreOJ/2239/data/bridge1.out create mode 100644 LibreOJ/2239/data/bridge10.in create mode 100644 LibreOJ/2239/data/bridge10.out create mode 100644 LibreOJ/2239/data/bridge2.in create mode 100644 LibreOJ/2239/data/bridge2.out create mode 100644 LibreOJ/2239/data/bridge3.in create mode 100644 LibreOJ/2239/data/bridge3.out create mode 100644 LibreOJ/2239/data/bridge4.in create mode 100644 LibreOJ/2239/data/bridge4.out create mode 100644 LibreOJ/2239/data/bridge5.in create mode 100644 LibreOJ/2239/data/bridge5.out create mode 100644 LibreOJ/2239/data/bridge6.in create mode 100644 LibreOJ/2239/data/bridge6.out create mode 100644 LibreOJ/2239/data/bridge7.in create mode 100644 LibreOJ/2239/data/bridge7.out create mode 100644 LibreOJ/2239/data/bridge8.in create mode 100644 LibreOJ/2239/data/bridge8.out create mode 100644 LibreOJ/2239/data/bridge9.in create mode 100644 LibreOJ/2239/data/bridge9.out diff --git a/LibreOJ/2239/2239.cpp b/LibreOJ/2239/2239.cpp new file mode 100644 index 00000000..9a6e4e60 --- /dev/null +++ b/LibreOJ/2239/2239.cpp @@ -0,0 +1,147 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 55, + M = (N * N) << 1; +const int INF = 0x3f3f3f3f; + +int n, s, t, a1, a2, an, b1, b2, bn; +int idx, head[N], head2[N], ver[M << 1], edge[M << 1], edge2[M << 1], next[M << 1]; +int dis[N], cur[N]; + +void add(int u, int v, int w) { + next[idx] = head[u]; + ver[idx] = v; + edge[idx] = w; + head[u] = idx++; +} + +bool bfs() { + std::fill(std::begin(dis), std::end(dis), 0); + + std::queue q; + + q.emplace(s); + dis[s] = 1; + cur[s] = head[s]; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + for (int i = head[u]; ~i; i = next[i]) { + int v = ver[i], + w = edge[i]; + + if (w && !dis[v]) { + dis[v] = dis[u] + 1; + cur[v] = head[v]; + + if (v == t) return true; + + q.emplace(v); + } + } + } + + return false; +} + +int dinic(int u, int limit) { + if (u == t) return limit; + + int flow = 0; + for (int i = cur[u]; ~i && flow < limit; i = next[i]) { + cur[u] = i; + + int v = ver[i], + w = edge[i]; + + if (w && dis[v] == dis[u] + 1) { + int k = dinic(v, std::min(w, limit - flow)); + + if (!k) dis[v] = 0; + + edge[i] -= k; + edge[i ^ 1] += k; + flow += k; + } + } + + return flow; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + while (cin >> n >> a1 >> a2 >> an >> b1 >> b2 >> bn) { + a1++, a2++, b1++, b2++; + s = 0, t = n + 1; + + idx = 0; + std::fill(std::begin(head), std::end(head), -1); + + for (int i = 1; i <= n; i++) { + for (int j = 1; j <= n; j++) { + char c; + + cin >> c; + + if (c == 'O') { + add(i, j, 2); + add(j, i, 0); + } else if (c == 'N') { + add(i, j, INF); + add(j, i, 0); + } + } + } + + bool ans = true; + + for (int _ = 0; _ < 2; _++) { + // Backup + int idx2 = idx; + std::copy(std::begin(head), std::end(head), std::begin(head2)); + std::copy(std::begin(edge), std::end(edge), std::begin(edge2)); + + add(s, a1, an * 2); + add(a1, s, 0); + + add(s, b1, bn * 2); + add(b1, s, 0); + + add(a2, t, an * 2); + add(t, a2, 0); + + add(b2, t, bn * 2); + add(t, b2, 0); + + int res = 0; + + while (bfs()) { + while (int flow = dinic(s, INF)) res += flow; + } + + ans &= res == (an + bn) * 2; + + std::swap(b1, b2); + + // Restore backup + idx = idx2; + std::copy(std::begin(head2), std::end(head2), std::begin(head)); + std::copy(std::begin(edge2), std::end(edge2), std::begin(edge)); + } + + cout << (ans ? "Yes" : "No") << endl; + } + + return 0; +} diff --git a/LibreOJ/2239/data/bridge1.in b/LibreOJ/2239/data/bridge1.in new file mode 100644 index 00000000..8f332b30 --- /dev/null +++ b/LibreOJ/2239/data/bridge1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:445e02cf3295551627f23969e262449d3dc7b55899df587f81a54312b7bee457 +size 494 diff --git a/LibreOJ/2239/data/bridge1.out b/LibreOJ/2239/data/bridge1.out new file mode 100644 index 00000000..4536e6d7 --- /dev/null +++ b/LibreOJ/2239/data/bridge1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:59e581b2b0b12d0369f29126dcfc0429bc5037ac917fcdc133960712a10561f6 +size 29 diff --git a/LibreOJ/2239/data/bridge10.in b/LibreOJ/2239/data/bridge10.in new file mode 100644 index 00000000..522aba3e --- /dev/null +++ b/LibreOJ/2239/data/bridge10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d3f9b51a6b01d3d3aa8a3a6cf2f1954cd0f87970b9f16f0d619127a47021c0fd +size 25180 diff --git a/LibreOJ/2239/data/bridge10.out b/LibreOJ/2239/data/bridge10.out new file mode 100644 index 00000000..b133dc3e --- /dev/null +++ b/LibreOJ/2239/data/bridge10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5644c88f5da65969b21ecdf9eb88603eabe218d7eece7beeb4cb6756c71675ce +size 74 diff --git a/LibreOJ/2239/data/bridge2.in b/LibreOJ/2239/data/bridge2.in new file mode 100644 index 00000000..3a5f3777 --- /dev/null +++ b/LibreOJ/2239/data/bridge2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:16bd9959d4587bb50d1d8d24e79b1ba79975b178a1c83708830a3557f7b91d2f +size 1600 diff --git a/LibreOJ/2239/data/bridge2.out b/LibreOJ/2239/data/bridge2.out new file mode 100644 index 00000000..98747766 --- /dev/null +++ b/LibreOJ/2239/data/bridge2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8e3fb5c6f618de276b6d53c123dd4be7c5fdf85fdd7d02555fb9ca6cddb47c55 +size 88 diff --git a/LibreOJ/2239/data/bridge3.in b/LibreOJ/2239/data/bridge3.in new file mode 100644 index 00000000..1c039a40 --- /dev/null +++ b/LibreOJ/2239/data/bridge3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:613f283e048df640a8efa2128cf1950e5ffe92483d6f0a4ed85067a6141f403d +size 2777 diff --git a/LibreOJ/2239/data/bridge3.out b/LibreOJ/2239/data/bridge3.out new file mode 100644 index 00000000..6b51e48b --- /dev/null +++ b/LibreOJ/2239/data/bridge3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cf988e9410a245f117b039afbfc85a1111b3b1eca760825282547096d106352d +size 55 diff --git a/LibreOJ/2239/data/bridge4.in b/LibreOJ/2239/data/bridge4.in new file mode 100644 index 00000000..cae19269 --- /dev/null +++ b/LibreOJ/2239/data/bridge4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f99a473719e8971ffa9f7faa4a9e834846a58eadc3fe0be86b70a437d0d40ed5 +size 10915 diff --git a/LibreOJ/2239/data/bridge4.out b/LibreOJ/2239/data/bridge4.out new file mode 100644 index 00000000..88dbbbcc --- /dev/null +++ b/LibreOJ/2239/data/bridge4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e0f00253f1b2c1350aabe9deffe48346462683d14c65e9d73aeae5843a6c01ec +size 52 diff --git a/LibreOJ/2239/data/bridge5.in b/LibreOJ/2239/data/bridge5.in new file mode 100644 index 00000000..93a3fda2 --- /dev/null +++ b/LibreOJ/2239/data/bridge5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:411576b247e4a28dcab012a5623fd10cf5d24da7718bec502ae1c86630b5cd42 +size 9084 diff --git a/LibreOJ/2239/data/bridge5.out b/LibreOJ/2239/data/bridge5.out new file mode 100644 index 00000000..766cdb7d --- /dev/null +++ b/LibreOJ/2239/data/bridge5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:706cf5460486b8af509808c1dd28efdb012c71504bb888e18a36f34fa61862c1 +size 39 diff --git a/LibreOJ/2239/data/bridge6.in b/LibreOJ/2239/data/bridge6.in new file mode 100644 index 00000000..b90977c3 --- /dev/null +++ b/LibreOJ/2239/data/bridge6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:de05b23802651a1382876594902afc392a385ed7b41c0d21c829a714917bfe09 +size 8217 diff --git a/LibreOJ/2239/data/bridge6.out b/LibreOJ/2239/data/bridge6.out new file mode 100644 index 00000000..449ed12e --- /dev/null +++ b/LibreOJ/2239/data/bridge6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:10ebf4f2cd1c4341530dc99f4d3118b3a9cf73ad1415181d070bf62aae7f2d40 +size 48 diff --git a/LibreOJ/2239/data/bridge7.in b/LibreOJ/2239/data/bridge7.in new file mode 100644 index 00000000..00aabb1c --- /dev/null +++ b/LibreOJ/2239/data/bridge7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1a3af2108b3950f5684fedaa971a5b6cdb8fb13499b13dcc0261f5b2326c2ef0 +size 11142 diff --git a/LibreOJ/2239/data/bridge7.out b/LibreOJ/2239/data/bridge7.out new file mode 100644 index 00000000..a0d8564a --- /dev/null +++ b/LibreOJ/2239/data/bridge7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bddc23cc5ac9cef5a3e57e7be70602569788869de6df496b72b44bbc2edf50a1 +size 41 diff --git a/LibreOJ/2239/data/bridge8.in b/LibreOJ/2239/data/bridge8.in new file mode 100644 index 00000000..de334847 --- /dev/null +++ b/LibreOJ/2239/data/bridge8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cbd7616a31ddc8e9964e8c63a4e92ddbe6a122f6a7c64e12e50cab251915a65c +size 14290 diff --git a/LibreOJ/2239/data/bridge8.out b/LibreOJ/2239/data/bridge8.out new file mode 100644 index 00000000..e412ee77 --- /dev/null +++ b/LibreOJ/2239/data/bridge8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:88e6eb13c9fc2aeed59de21ef2388e94d10d0b7227addfba3c239919443b143e +size 34 diff --git a/LibreOJ/2239/data/bridge9.in b/LibreOJ/2239/data/bridge9.in new file mode 100644 index 00000000..751112ae --- /dev/null +++ b/LibreOJ/2239/data/bridge9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ceaaf4be066ee48a8b4d2aa39f67f1d8b4477011422710f8b4ed8491922079d4 +size 23469 diff --git a/LibreOJ/2239/data/bridge9.out b/LibreOJ/2239/data/bridge9.out new file mode 100644 index 00000000..fdc1101a --- /dev/null +++ b/LibreOJ/2239/data/bridge9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:29cb3006e05e3a926541c3f8e72d7ee4da60d4595ec23b68a0c81193509dfc9f +size 69