From 6b8800472de9b5659413a3a07e00b9ebeb4d840a Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Tue, 22 Mar 2022 16:23:28 +0800 Subject: [PATCH] =?UTF-8?q?#101.=20=E6=9C=80=E5=A4=A7=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://loj.ac/s/1419660 --- LibreOJ/101/101.cpp | 94 ++++++++++++++++++++++++++++++++++++++++++ LibreOJ/101/data/1.in | 3 ++ LibreOJ/101/data/1.out | 3 ++ LibreOJ/101/data/2.in | 3 ++ LibreOJ/101/data/2.out | 3 ++ LibreOJ/101/data/3.in | 3 ++ LibreOJ/101/data/3.out | 3 ++ LibreOJ/101/data/4.in | 3 ++ LibreOJ/101/data/4.out | 3 ++ LibreOJ/101/data/5.in | 3 ++ LibreOJ/101/data/5.out | 3 ++ LibreOJ/101/data/6.in | 3 ++ LibreOJ/101/data/6.out | 3 ++ LibreOJ/101/data/7.in | 3 ++ LibreOJ/101/data/7.out | 3 ++ LibreOJ/101/data/8.in | 3 ++ LibreOJ/101/data/8.out | 3 ++ 17 files changed, 142 insertions(+) create mode 100644 LibreOJ/101/101.cpp create mode 100644 LibreOJ/101/data/1.in create mode 100644 LibreOJ/101/data/1.out create mode 100644 LibreOJ/101/data/2.in create mode 100644 LibreOJ/101/data/2.out create mode 100644 LibreOJ/101/data/3.in create mode 100644 LibreOJ/101/data/3.out create mode 100644 LibreOJ/101/data/4.in create mode 100644 LibreOJ/101/data/4.out create mode 100644 LibreOJ/101/data/5.in create mode 100644 LibreOJ/101/data/5.out create mode 100644 LibreOJ/101/data/6.in create mode 100644 LibreOJ/101/data/6.out create mode 100644 LibreOJ/101/data/7.in create mode 100644 LibreOJ/101/data/7.out create mode 100644 LibreOJ/101/data/8.in create mode 100644 LibreOJ/101/data/8.out diff --git a/LibreOJ/101/101.cpp b/LibreOJ/101/101.cpp new file mode 100644 index 00000000..de20fbbb --- /dev/null +++ b/LibreOJ/101/101.cpp @@ -0,0 +1,94 @@ +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 105, + M = 5005; + +int n, m, s, t, flow; +long long ans; + +// Graph +int idx, head[N], ver[M << 1], edge[M << 1], next[M << 1]; + +void add(int u, int v, int w) { + next[idx] = head[u]; + ver[idx] = v; + edge[idx] = w; + head[u] = idx++; +} + +// Dinic +int d[N], cur[N]; + +bool bfs() { + memset(d, 0x00, sizeof(d)); + + std::queue q; + q.push(s); + d[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 (!d[v] && w) { + d[v] = d[u] + 1; + cur[v] = head[v]; + if (v == t) return true; + q.push(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]) { + int v = ver[i], + w = edge[i]; + if (d[v] == d[u] + 1 && w) { + int k = dinic(v, std::min(w, limit - flow)); + if (!k) d[v] = 0; + edge[i] -= k; + edge[i ^ 1] += k; + flow += k; + } + } + + return flow; +} + +int main() { + std::ios::sync_with_stdio(false); + + memset(head, 0xff, sizeof(head)); + + cin >> n >> m >> s >> t; + for (int i = 1; i <= m; i++) { + int u, v, w; + cin >> u >> v >> w; + add(u, v, w); + add(v, u, 0); + } + + while (bfs()) { + while (flow = dinic(s, std::numeric_limits::max())) ans += flow; + } + + cout << ans << endl; + + return 0; +} diff --git a/LibreOJ/101/data/1.in b/LibreOJ/101/data/1.in new file mode 100644 index 00000000..5e5cc629 --- /dev/null +++ b/LibreOJ/101/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:73dc0e159216929d20228dd9f25d9591ec24ae18d6c5ac69ceb78d61d580b14f +size 2353 diff --git a/LibreOJ/101/data/1.out b/LibreOJ/101/data/1.out new file mode 100644 index 00000000..a7b25667 --- /dev/null +++ b/LibreOJ/101/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f167f2fcbf3c641b8857e859ba871b5feb29f5a1f6ce3255861057b0d65549e8 +size 4 diff --git a/LibreOJ/101/data/2.in b/LibreOJ/101/data/2.in new file mode 100644 index 00000000..d396ec67 --- /dev/null +++ b/LibreOJ/101/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22377cd244ca1180a1153764b686af75ba420e8e577c9230b6659e81174ae4f0 +size 55579 diff --git a/LibreOJ/101/data/2.out b/LibreOJ/101/data/2.out new file mode 100644 index 00000000..6ce00fc5 --- /dev/null +++ b/LibreOJ/101/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6e8efce90e2b45f7726f6f7a1a49ebb945ffaf14abade241263a6029a3afbb71 +size 8 diff --git a/LibreOJ/101/data/3.in b/LibreOJ/101/data/3.in new file mode 100644 index 00000000..e2024eb0 --- /dev/null +++ b/LibreOJ/101/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:33c00ea4eac5ea0fb2090fc2e8a3cbe6d48c83b0088243004f2a56e3b320dea6 +size 9128 diff --git a/LibreOJ/101/data/3.out b/LibreOJ/101/data/3.out new file mode 100644 index 00000000..c1b004e3 --- /dev/null +++ b/LibreOJ/101/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2fb342c893b14573229d05660c63c328e0df1d2167ee0f99035a4a6188d69948 +size 5 diff --git a/LibreOJ/101/data/4.in b/LibreOJ/101/data/4.in new file mode 100644 index 00000000..e755a2c8 --- /dev/null +++ b/LibreOJ/101/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ba319e9dc9c8fd315bffeecacfb99b188247410881374bc66a59a65f5016fa99 +size 8171 diff --git a/LibreOJ/101/data/4.out b/LibreOJ/101/data/4.out new file mode 100644 index 00000000..5fb00cbf --- /dev/null +++ b/LibreOJ/101/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:43b6eed17ab6dacc4d288654c558c903392a52947d7734f2c205276530c5d6e2 +size 11 diff --git a/LibreOJ/101/data/5.in b/LibreOJ/101/data/5.in new file mode 100644 index 00000000..fde9e15a --- /dev/null +++ b/LibreOJ/101/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9c2edbc19f4a198ad327a229949eaed355cd613cd5fa743cc3caec02f2bfa528 +size 24510 diff --git a/LibreOJ/101/data/5.out b/LibreOJ/101/data/5.out new file mode 100644 index 00000000..b24f6e50 --- /dev/null +++ b/LibreOJ/101/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:711705b8d16758ada9c9de622d69b10052bd7258acb69fa33c6bed20855083f4 +size 12 diff --git a/LibreOJ/101/data/6.in b/LibreOJ/101/data/6.in new file mode 100644 index 00000000..5249e574 --- /dev/null +++ b/LibreOJ/101/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:00ba1dfe41820fbe035e2fd392593c237ae80e169702300044edbdb7db6aa0f8 +size 81645 diff --git a/LibreOJ/101/data/6.out b/LibreOJ/101/data/6.out new file mode 100644 index 00000000..f1f17ae0 --- /dev/null +++ b/LibreOJ/101/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a43c9e1994ba69f71ae87b0dc5f76471f58c8bd492a2f951236bc452f408fa85 +size 12 diff --git a/LibreOJ/101/data/7.in b/LibreOJ/101/data/7.in new file mode 100644 index 00000000..22f47b20 --- /dev/null +++ b/LibreOJ/101/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a72c3216a05ad52a3633165c6e389871753ea45965630eaf1f93fb7a1e82b3d +size 64037 diff --git a/LibreOJ/101/data/7.out b/LibreOJ/101/data/7.out new file mode 100644 index 00000000..49738d7a --- /dev/null +++ b/LibreOJ/101/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ffe2c24f5275027b5e6a7d1493f613d3598edebd8bc8d1044d3c4cb37714e3a +size 11 diff --git a/LibreOJ/101/data/8.in b/LibreOJ/101/data/8.in new file mode 100644 index 00000000..287e4378 --- /dev/null +++ b/LibreOJ/101/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fb6e647db02951d2e4ab83266b51df655951d9880c244714e68786fdba848eb3 +size 64118 diff --git a/LibreOJ/101/data/8.out b/LibreOJ/101/data/8.out new file mode 100644 index 00000000..0284a4db --- /dev/null +++ b/LibreOJ/101/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cd94fcac874a4f568b730c9ae315545cef42ef6e96fd0fe501acbf6b93fe3165 +size 11