diff --git a/BZOJ/1391/1391.cpp b/BZOJ/1391/1391.cpp new file mode 100644 index 00000000..500f87f5 --- /dev/null +++ b/BZOJ/1391/1391.cpp @@ -0,0 +1,126 @@ +#pragma GCC optimize("Ofast") + +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 2e6 + 5; + +int n, m, s, t, sum; +int idx, head[N], edge[N << 1], ver[N << 1], next[N << 1]; +int dist[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() { + memset(dist, 0x00, sizeof(dist)); + + std::queue q; + + dist[s] = 1; + q.push(s); + 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 && !dist[v]) { + 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 (w && dist[v] == dist[u] + 1) { + int k = dinic(v, std::min(limit - flow, w)); + + 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; + + s = 0, t = n + m + 1; + + for (int i = 1; i <= n; i++) { + int x, t; + + cin >> x >> t; + + add(s, i, x); + add(i, s, 0); + sum += x; + + for (int j = 1; j <= t; j++) { + int a, b; + + cin >> a >> b; + + add(i, a + n, b); + add(a + n, i, 0); + } + } + + for (int i = 1; i <= m; i++) { + int y; + + cin >> y; + + add(i + n, t, y); + add(t, i + n, 0); + } + + int res = 0, flow; + while (bfs()) { + while (flow = dinic(s, std::numeric_limits::max())) res += flow; + } + + cout << sum - res << endl; + + return 0; +} diff --git a/BZOJ/1391/data/1.in b/BZOJ/1391/data/1.in new file mode 100644 index 00000000..c16e2b16 --- /dev/null +++ b/BZOJ/1391/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ac141c28811152d30cdd45509b38f230d63a815cb93cec2ec6271a870233cbd0 +size 1067 diff --git a/BZOJ/1391/data/1.out b/BZOJ/1391/data/1.out new file mode 100644 index 00000000..203340f6 --- /dev/null +++ b/BZOJ/1391/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69253609b6e151455b4f4e746cc0eabe67d8611a459e101a037db311577ae07d +size 5 diff --git a/BZOJ/1391/data/10.in b/BZOJ/1391/data/10.in new file mode 100644 index 00000000..5cbfbea3 --- /dev/null +++ b/BZOJ/1391/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bee07264d285018b460bcefaace3b99615bb793a2684f56093f6612c84d99844 +size 234 diff --git a/BZOJ/1391/data/10.out b/BZOJ/1391/data/10.out new file mode 100644 index 00000000..46147255 --- /dev/null +++ b/BZOJ/1391/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d35afb174a7f8cee01b12d840310722409dfce5ae07492ccd5dd346eb94ad661 +size 4 diff --git a/BZOJ/1391/data/11.in b/BZOJ/1391/data/11.in new file mode 100644 index 00000000..d8268784 --- /dev/null +++ b/BZOJ/1391/data/11.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b11456e2f9dcb3c2ad08bb04d05edf1ee7cb00dfc614f84cce613a6f77fec4cc +size 7693394 diff --git a/BZOJ/1391/data/11.out b/BZOJ/1391/data/11.out new file mode 100644 index 00000000..beae442c --- /dev/null +++ b/BZOJ/1391/data/11.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2c861eb667f6330d64a41415abe5deb6619c0bb8027bab5e4c41632c69fbe39d +size 8 diff --git a/BZOJ/1391/data/12.in b/BZOJ/1391/data/12.in new file mode 100644 index 00000000..cba79781 --- /dev/null +++ b/BZOJ/1391/data/12.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0fe0c6a8add98ff3e9c254812a07dfdd66dea1d98966004d8c695968cda3a4ce +size 3105524 diff --git a/BZOJ/1391/data/12.out b/BZOJ/1391/data/12.out new file mode 100644 index 00000000..75ee0cba --- /dev/null +++ b/BZOJ/1391/data/12.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:566f9b4706e96e05598b12ff6dcfc5130699c8efe4738639130e289e6fa4294c +size 7 diff --git a/BZOJ/1391/data/13.in b/BZOJ/1391/data/13.in new file mode 100644 index 00000000..a090d1f0 --- /dev/null +++ b/BZOJ/1391/data/13.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e21e7db242b64389e69ecda058e3856f8b7e353392afc14d7b56ed818b97f156 +size 22582 diff --git a/BZOJ/1391/data/13.out b/BZOJ/1391/data/13.out new file mode 100644 index 00000000..b4fc4856 --- /dev/null +++ b/BZOJ/1391/data/13.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6337a2226c13edac1515782bb3dde631f04171dd4f9072681431d65d9007f2a +size 7 diff --git a/BZOJ/1391/data/14.in b/BZOJ/1391/data/14.in new file mode 100644 index 00000000..d80e9daa --- /dev/null +++ b/BZOJ/1391/data/14.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ff172945b77d114b64ffe49a7aebddc64dc6ecb3349246148be40b94d883ed5c +size 212 diff --git a/BZOJ/1391/data/14.out b/BZOJ/1391/data/14.out new file mode 100644 index 00000000..34b8306d --- /dev/null +++ b/BZOJ/1391/data/14.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:66c342932aa7c18f7bf1fa212aa011069fc2e50e0c7e9e4c73fcaa6851854c47 +size 4 diff --git a/BZOJ/1391/data/15.in b/BZOJ/1391/data/15.in new file mode 100644 index 00000000..ab6d478b --- /dev/null +++ b/BZOJ/1391/data/15.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:023dbd1de12b1c9c9f9b7b8a334a2882a2e3ac21ba03890b55828f94f6cc93e8 +size 1942205 diff --git a/BZOJ/1391/data/15.out b/BZOJ/1391/data/15.out new file mode 100644 index 00000000..59a438eb --- /dev/null +++ b/BZOJ/1391/data/15.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:86a6a72e46a053423c465e09156ff7c1a58ba55e3c6ade17be1f54e980a30e40 +size 8 diff --git a/BZOJ/1391/data/16.in b/BZOJ/1391/data/16.in new file mode 100644 index 00000000..5e183084 --- /dev/null +++ b/BZOJ/1391/data/16.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:791112d7f2a18b4199726c50b76152ffc8b14a23c83e5c975ff36b13a7fb107e +size 8803595 diff --git a/BZOJ/1391/data/16.out b/BZOJ/1391/data/16.out new file mode 100644 index 00000000..b2d30944 --- /dev/null +++ b/BZOJ/1391/data/16.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6c5224b981c0c5db0b3307bef42ea8c5edc469aad90de53c37514a4912d22ec4 +size 7 diff --git a/BZOJ/1391/data/17.in b/BZOJ/1391/data/17.in new file mode 100644 index 00000000..cd7e5a91 --- /dev/null +++ b/BZOJ/1391/data/17.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:36f04ece0c92b1ee74492e3bba4acf5370ff5ac13a31e74df32a571539e1268a +size 87 diff --git a/BZOJ/1391/data/17.out b/BZOJ/1391/data/17.out new file mode 100644 index 00000000..7e7613cc --- /dev/null +++ b/BZOJ/1391/data/17.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4a144adfc7753e93682285733402c2cc2afa2af9cd933aa06ea5f39d33fa6b8 +size 4 diff --git a/BZOJ/1391/data/18.in b/BZOJ/1391/data/18.in new file mode 100644 index 00000000..9b8e1c31 --- /dev/null +++ b/BZOJ/1391/data/18.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:79085a305bbd0cc6cace1c826bbfad542b72d575d76efc6fc1dc0f624079ca6d +size 400 diff --git a/BZOJ/1391/data/18.out b/BZOJ/1391/data/18.out new file mode 100644 index 00000000..804fcc90 --- /dev/null +++ b/BZOJ/1391/data/18.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9a271f2a916b0b6ee6cecb2426f0b3206ef074578be55d9bc94f6f3fe3ab86aa +size 2 diff --git a/BZOJ/1391/data/2.in b/BZOJ/1391/data/2.in new file mode 100644 index 00000000..555eb4db --- /dev/null +++ b/BZOJ/1391/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5bf17011ff58cc57ac19c37b77f7857483c81ecbcd8ce3ca777e471ee97f7354 +size 1400 diff --git a/BZOJ/1391/data/2.out b/BZOJ/1391/data/2.out new file mode 100644 index 00000000..ee39c1a0 --- /dev/null +++ b/BZOJ/1391/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c5aeba7f7b48e1efc2d73205a4e08c186a7adba1063902c8077d4a999c881a26 +size 5 diff --git a/BZOJ/1391/data/3.in b/BZOJ/1391/data/3.in new file mode 100644 index 00000000..4aab6229 --- /dev/null +++ b/BZOJ/1391/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f6447fcc3334f89558bee79fe0ca705a2592577d876f28e7076f0fec6a1047ae +size 46 diff --git a/BZOJ/1391/data/3.out b/BZOJ/1391/data/3.out new file mode 100644 index 00000000..db27dc9a --- /dev/null +++ b/BZOJ/1391/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7ea9844ae84eccbf55e8330640865e36c43521e45a1baec24233327aab7e6595 +size 3 diff --git a/BZOJ/1391/data/4.in b/BZOJ/1391/data/4.in new file mode 100644 index 00000000..6026af83 --- /dev/null +++ b/BZOJ/1391/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d9dfe8614ff563b6a12b00a6a1933a4f41765bafe54208028c2634e88858c2be +size 186 diff --git a/BZOJ/1391/data/4.out b/BZOJ/1391/data/4.out new file mode 100644 index 00000000..c4217dfd --- /dev/null +++ b/BZOJ/1391/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d93844f8f37e55564be3f194656bf33b5d0fb5e589a0fe17eb7c2d4e8593ec9c +size 3 diff --git a/BZOJ/1391/data/5.in b/BZOJ/1391/data/5.in new file mode 100644 index 00000000..7fbb3d90 --- /dev/null +++ b/BZOJ/1391/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f71fea6c841d72e05dde89272761f2dfddb229f0d7978d65fdca55ac13304f91 +size 18527 diff --git a/BZOJ/1391/data/5.out b/BZOJ/1391/data/5.out new file mode 100644 index 00000000..13751733 --- /dev/null +++ b/BZOJ/1391/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:22dce3863825bffe34927193897a0ccf90e7154757236cb2cbbdb37dc83889a5 +size 7 diff --git a/BZOJ/1391/data/6.in b/BZOJ/1391/data/6.in new file mode 100644 index 00000000..6fe6677b --- /dev/null +++ b/BZOJ/1391/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4d453cc2984622cab4da3356fe91937dfdbeb62f655d43c8222c87433f0e7bdd +size 8789843 diff --git a/BZOJ/1391/data/6.out b/BZOJ/1391/data/6.out new file mode 100644 index 00000000..061699d0 --- /dev/null +++ b/BZOJ/1391/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfe70430e94953f63409f77d7682b0c51f6ee3a3341dd15a96ad257aa9877e8f +size 7 diff --git a/BZOJ/1391/data/7.in b/BZOJ/1391/data/7.in new file mode 100644 index 00000000..e5ddf9ed --- /dev/null +++ b/BZOJ/1391/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:684ed304843c83a6b01280aa4abe8d9dde92b096219fd92b8df8c0cf270f2f4f +size 25493 diff --git a/BZOJ/1391/data/7.out b/BZOJ/1391/data/7.out new file mode 100644 index 00000000..06ca7aba --- /dev/null +++ b/BZOJ/1391/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:40cb4369c5fbe0ad4cc9e295b025ac8e5b24b8ab1ae249f87f75589ce3b8b898 +size 6 diff --git a/BZOJ/1391/data/8.in b/BZOJ/1391/data/8.in new file mode 100644 index 00000000..aed56e3c --- /dev/null +++ b/BZOJ/1391/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:62f87f1d23abb7803bfe7094d6700e6dd44aa0b0d8b678a737847ddeb79ffa19 +size 5163 diff --git a/BZOJ/1391/data/8.out b/BZOJ/1391/data/8.out new file mode 100644 index 00000000..37d789ab --- /dev/null +++ b/BZOJ/1391/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:19b475910ee9ba3f7199cbe69292a0034dc313f788ccfb67cd83f472e95f885d +size 5 diff --git a/BZOJ/1391/data/9.in b/BZOJ/1391/data/9.in new file mode 100644 index 00000000..af1f954f --- /dev/null +++ b/BZOJ/1391/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7cc9c19dfbac5842ada201b1edf48b7be6ade56e9eb4c463b2a67a6c9ed4cf22 +size 6965 diff --git a/BZOJ/1391/data/9.out b/BZOJ/1391/data/9.out new file mode 100644 index 00000000..d30fc0e3 --- /dev/null +++ b/BZOJ/1391/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f4358194b73cddf05d80a1b3669b7db2e21516d55a156102fb60d3448ca91c38 +size 6