diff --git a/LibreOJ/117/117.cpp b/LibreOJ/117/117.cpp new file mode 100644 index 00000000..8cb4aa53 --- /dev/null +++ b/LibreOJ/117/117.cpp @@ -0,0 +1,133 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 5e4 + 5, + M = 125003 + 5; + +int n, m, s, t, ss, tt; +int idx, head[N], ver[M << 2], edge[M << 2], next[M << 2]; +int f[N], cur[N], dist[N]; + +void add(int u, int v, int w) { + ver[idx] = v; + edge[idx] = w; + next[idx] = head[u]; + head[u] = idx++; +} + +bool bfs() { + memset(dist, 0x00, sizeof(dist)); + + std::queue q; + + q.push(s); + dist[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 (!dist[v] && w) { + dist[v] = dist[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]) { + cur[u] = i; + + int v = ver[i], + w = edge[i]; + + if (dist[v] == dist[u] + 1 && w) { + int k = dinic(v, std::min(w, limit - flow)); + + if (!k) dist[v] = 0; + edge[i] -= k; + edge[i ^ 1] += k; + flow += k; + } + } + + return flow; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + memset(head, 0xff, sizeof(head)); + + cin >> n >> m >> ss >> tt; + + for (int i = 1, u, v, a, b; i <= m; i++) { + cin >> u >> v >> a >> b; + + add(u, v, b - a); + add(v, u, 0); + + f[u] -= a, f[v] += a; + } + + int sum = 0; + s = 0, t = n + 1; + + for (int i = 1; i <= n; i++) { + if (f[i] > 0) { + add(s, i, f[i]); + add(i, s, 0); + sum += f[i]; + } else if (f[i] < 0) { + add(i, t, -f[i]); + add(t, i, 0); + } + } + + add(tt, ss, std::numeric_limits::max()); + add(ss, tt, 0); + + int res = 0, flow; + while (bfs()) { + while (flow = dinic(s, std::numeric_limits::max())) res += flow; + } + + if (res == sum) { + int x = edge[idx - 1]; + edge[idx - 1] = edge[idx - 2] = 0; + + s = tt, t = ss; + + int res = 0, flow; + while (bfs()) { + while (flow = dinic(s, std::numeric_limits::max())) res += flow; + } + + cout << x - res << endl; + } else { + cout << "please go home to sleep" << endl; + } + + return 0; +} diff --git a/LibreOJ/117/data/0.in b/LibreOJ/117/data/0.in new file mode 100644 index 00000000..9b339545 --- /dev/null +++ b/LibreOJ/117/data/0.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8583cbbaab697bfefa4e85ce85ed1c364cbb1886c600407b96bb6db140cbba0b +size 34 diff --git a/LibreOJ/117/data/0.out b/LibreOJ/117/data/0.out new file mode 100644 index 00000000..77f13176 --- /dev/null +++ b/LibreOJ/117/data/0.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:410cde41d9d01456465809d40a3e5f9caa2cd535d6b25b1e5e2b0690e9363655 +size 24 diff --git a/LibreOJ/117/data/1.in b/LibreOJ/117/data/1.in new file mode 100644 index 00000000..06894062 --- /dev/null +++ b/LibreOJ/117/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f8bd583b487fc5df8e2be7e9a9045d356461ce318eb75eec3ada2a55268a6555 +size 264 diff --git a/LibreOJ/117/data/1.out b/LibreOJ/117/data/1.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/LibreOJ/117/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2 diff --git a/LibreOJ/117/data/10.in b/LibreOJ/117/data/10.in new file mode 100644 index 00000000..47d8a5ab --- /dev/null +++ b/LibreOJ/117/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a806f0c6b7b6944a50db1ead7ff4835c4815a4a4e2e4f9622c99a3d64a73bab2 +size 2483818 diff --git a/LibreOJ/117/data/10.out b/LibreOJ/117/data/10.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/LibreOJ/117/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/LibreOJ/117/data/11.in b/LibreOJ/117/data/11.in new file mode 100644 index 00000000..e91a3834 --- /dev/null +++ b/LibreOJ/117/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d41baa06a65c3e448c95815ee093acdc04e19590887a2d473e3b95cb99ca305b +size 232265 diff --git a/LibreOJ/117/data/11.out b/LibreOJ/117/data/11.out new file mode 100644 index 00000000..7ec9693c --- /dev/null +++ b/LibreOJ/117/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:39b8dc3fc8b44765c8e6f1adee04c5b465e555ab791cc42d0d9e810d5b64297c +size 4 diff --git a/LibreOJ/117/data/12.in b/LibreOJ/117/data/12.in new file mode 100644 index 00000000..f6f25fb6 --- /dev/null +++ b/LibreOJ/117/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f3604f1c7dc4a8f095fd3edc3c7ca561ecdde5a7357a4af1e62aecc07fc95549 +size 232327 diff --git a/LibreOJ/117/data/12.out b/LibreOJ/117/data/12.out new file mode 100644 index 00000000..a049d7c0 --- /dev/null +++ b/LibreOJ/117/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:45080860abd6d79b808dbd71836bf29e41918f1bf1f05f7ce732ada7674cc816 +size 4 diff --git a/LibreOJ/117/data/13.in b/LibreOJ/117/data/13.in new file mode 100644 index 00000000..3093063b --- /dev/null +++ b/LibreOJ/117/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e244d48452d1ff2506ba2c3c9a0049fcdfcb9dd5aa886f92376f149d78097962 +size 2492091 diff --git a/LibreOJ/117/data/13.out b/LibreOJ/117/data/13.out new file mode 100644 index 00000000..8ca041ea --- /dev/null +++ b/LibreOJ/117/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0590dbaeaad31be1063b2b2392e61fa3373fd004461eb50f77b8d67738092901 +size 4 diff --git a/LibreOJ/117/data/14.in b/LibreOJ/117/data/14.in new file mode 100644 index 00000000..6ab37a80 --- /dev/null +++ b/LibreOJ/117/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c8e2dbfe44e0301774c5acf2c781dabe47e8c94eea7e97181c78fcebd40910d +size 2491929 diff --git a/LibreOJ/117/data/14.out b/LibreOJ/117/data/14.out new file mode 100644 index 00000000..9ec5a1bb --- /dev/null +++ b/LibreOJ/117/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e6a4f0a1da38776f216b19ac7c8e6a3c2a8272de576ab2c6fb33867ddd8159f6 +size 4 diff --git a/LibreOJ/117/data/15.in b/LibreOJ/117/data/15.in new file mode 100644 index 00000000..d38afcfc --- /dev/null +++ b/LibreOJ/117/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5b7dd8a43ec66ecd2692440e6c7a157dbd0391400f32e1fa1cf246a7b87ca1e +size 480747 diff --git a/LibreOJ/117/data/15.out b/LibreOJ/117/data/15.out new file mode 100644 index 00000000..dff0a636 --- /dev/null +++ b/LibreOJ/117/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:95aebc97bc646c67fdcd923a5965b001f3c8a5c4d3a77075112e12a3a311d760 +size 3 diff --git a/LibreOJ/117/data/16.in b/LibreOJ/117/data/16.in new file mode 100644 index 00000000..7f1e5273 --- /dev/null +++ b/LibreOJ/117/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fd1b73eac27b2710881b7f6cb690fe7142d1f78b01da3f0d8e6ec62277368ac7 +size 480874 diff --git a/LibreOJ/117/data/16.out b/LibreOJ/117/data/16.out new file mode 100644 index 00000000..21b88a97 --- /dev/null +++ b/LibreOJ/117/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:461144ccfd56ee3cf0f9a9d80e520c5b872166b23092d5fd838ecbdb46d64dab +size 3 diff --git a/LibreOJ/117/data/17.in b/LibreOJ/117/data/17.in new file mode 100644 index 00000000..b11f4b25 --- /dev/null +++ b/LibreOJ/117/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e5cbd47d37038f161cda425747a77acc9c2559035f053bc67dcc483bc970efea +size 1483433 diff --git a/LibreOJ/117/data/17.out b/LibreOJ/117/data/17.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/LibreOJ/117/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2 diff --git a/LibreOJ/117/data/18.in b/LibreOJ/117/data/18.in new file mode 100644 index 00000000..fd9504e1 --- /dev/null +++ b/LibreOJ/117/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4ec96ca4edd2c53dd1e3caecf7f6670aa931ff9e0b4a43e517a49ac65e042bc7 +size 1481290 diff --git a/LibreOJ/117/data/18.out b/LibreOJ/117/data/18.out new file mode 100644 index 00000000..c8e32442 --- /dev/null +++ b/LibreOJ/117/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7e332bcee418f7d700927c946d36341f0651d6d90997b58d3d5441dec96b2e74 +size 3 diff --git a/LibreOJ/117/data/19.in b/LibreOJ/117/data/19.in new file mode 100644 index 00000000..71e6fa02 --- /dev/null +++ b/LibreOJ/117/data/19.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:94d66628506d3a19045ae5a09200c84318f297133b9b8af03c33ba181189a373 +size 2483548 diff --git a/LibreOJ/117/data/19.out b/LibreOJ/117/data/19.out new file mode 100644 index 00000000..901efe38 --- /dev/null +++ b/LibreOJ/117/data/19.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9d9b18720961e9b4689fd763b85e7b6f36160ccd3a8a1c9ddc5103bb0f66c396 +size 4 diff --git a/LibreOJ/117/data/2.in b/LibreOJ/117/data/2.in new file mode 100644 index 00000000..388bae95 --- /dev/null +++ b/LibreOJ/117/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:acc56b2344e1e21c827c523a1b1a7611f8d4d72ff6d5ad72eee94e487dc1b4cc +size 604 diff --git a/LibreOJ/117/data/2.out b/LibreOJ/117/data/2.out new file mode 100644 index 00000000..d595cdb8 --- /dev/null +++ b/LibreOJ/117/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7de1555df0c2700329e815b93b32c571c3ea54dc967b89e81ab73b9972b72d1d +size 2 diff --git a/LibreOJ/117/data/20.in b/LibreOJ/117/data/20.in new file mode 100644 index 00000000..f9deffaa --- /dev/null +++ b/LibreOJ/117/data/20.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:817eaa80860930417ca603667685b7fc647cea699f04ce1ad73c7267d52ae3e7 +size 2483176 diff --git a/LibreOJ/117/data/20.out b/LibreOJ/117/data/20.out new file mode 100644 index 00000000..abda6d0b --- /dev/null +++ b/LibreOJ/117/data/20.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:690e07064753123c967bbac0180f32da6a753a5bd8b79a47644cef58e776d9f0 +size 4 diff --git a/LibreOJ/117/data/3.in b/LibreOJ/117/data/3.in new file mode 100644 index 00000000..eb2353a0 --- /dev/null +++ b/LibreOJ/117/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a03c8123b0917a60d02b091bbd2e871a4c1e90c704ab3122945c2d42119a788 +size 4548 diff --git a/LibreOJ/117/data/3.out b/LibreOJ/117/data/3.out new file mode 100644 index 00000000..f4808fee --- /dev/null +++ b/LibreOJ/117/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:917df3320d778ddbaa5c5c7742bc4046bf803c36ed2b050f30844ed206783469 +size 3 diff --git a/LibreOJ/117/data/4.in b/LibreOJ/117/data/4.in new file mode 100644 index 00000000..c4f9177f --- /dev/null +++ b/LibreOJ/117/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:630c911aad3b0277376b7ac473026847d62bd5710ddb2b09e027cffea750edc0 +size 44872 diff --git a/LibreOJ/117/data/4.out b/LibreOJ/117/data/4.out new file mode 100644 index 00000000..d790bd49 --- /dev/null +++ b/LibreOJ/117/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e6d31a5983a91251bfae5aefa1c0a19d8ba3cf601d0e8a706b4cfa9661a6b8a +size 2 diff --git a/LibreOJ/117/data/5.in b/LibreOJ/117/data/5.in new file mode 100644 index 00000000..e955ff7e --- /dev/null +++ b/LibreOJ/117/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:47675e64a5253f61ad7bd95f0ab06358a85013d240765686a2901e5fbc4858d1 +size 285353 diff --git a/LibreOJ/117/data/5.out b/LibreOJ/117/data/5.out new file mode 100644 index 00000000..1afab5f7 --- /dev/null +++ b/LibreOJ/117/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4355a46b19d348dc2f57c046f8ef63d4538ebb936000f3c9ee954a27460dd865 +size 2 diff --git a/LibreOJ/117/data/6.in b/LibreOJ/117/data/6.in new file mode 100644 index 00000000..bd81ae88 --- /dev/null +++ b/LibreOJ/117/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f61adb07006b21d95f60da218556e1038314cfbc957ed230f0a9eaf6bbe98519 +size 284246 diff --git a/LibreOJ/117/data/6.out b/LibreOJ/117/data/6.out new file mode 100644 index 00000000..d0810087 --- /dev/null +++ b/LibreOJ/117/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f739882f40e2be8022d26517e0b963ab2351687845ebe1cf320efd0d0d3e388a +size 5 diff --git a/LibreOJ/117/data/7.in b/LibreOJ/117/data/7.in new file mode 100644 index 00000000..3a7e1959 --- /dev/null +++ b/LibreOJ/117/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2a34846700142e8fbc4fc00643267884a7bbd698571c531794168a76eee83d16 +size 3091782 diff --git a/LibreOJ/117/data/7.out b/LibreOJ/117/data/7.out new file mode 100644 index 00000000..487c7923 --- /dev/null +++ b/LibreOJ/117/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c9bff8071ee3a81fecc04f87b20aa2d35646d178a4c3a27d1a8e3353087a1ccf +size 6 diff --git a/LibreOJ/117/data/8.in b/LibreOJ/117/data/8.in new file mode 100644 index 00000000..0e2114ae --- /dev/null +++ b/LibreOJ/117/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b82dd0bb054589acee387073b82bbf11c7c72cf794e8ae8524cd351d3f9dc6b +size 230033 diff --git a/LibreOJ/117/data/8.out b/LibreOJ/117/data/8.out new file mode 100644 index 00000000..38118f32 --- /dev/null +++ b/LibreOJ/117/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:53c234e5e8472b6ac51c1ae1cab3fe06fad053beb8ebfd8977b010655bfdd3c3 +size 2 diff --git a/LibreOJ/117/data/9.in b/LibreOJ/117/data/9.in new file mode 100644 index 00000000..df122b08 --- /dev/null +++ b/LibreOJ/117/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3473914bc5cb1058b04ab3e521e866b5f76518876519628b2fb86608ae9a8e77 +size 2483538 diff --git a/LibreOJ/117/data/9.out b/LibreOJ/117/data/9.out new file mode 100644 index 00000000..ca267b30 --- /dev/null +++ b/LibreOJ/117/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1121cfccd5913f0a63fec40a6ffd44ea64f9dc135c66634ba001d10bcf4302a2 +size 2