diff --git a/S2OJ/1363/1363.cpp b/S2OJ/1363/1363.cpp new file mode 100644 index 00000000..f4651634 --- /dev/null +++ b/S2OJ/1363/1363.cpp @@ -0,0 +1,121 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int INF = 0x3f3f3f3f; + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + int t; + + cin >> t; + + while (t--) { + int n, m; + + cin >> n >> m; + + int s = 0, t = 1; + std::vector a(n + 1), pre(n + 1), head((m + 1) << 1, -1); + std::vector> edges; + + for (int i = 1; i <= n; i++) { + cin >> a[i]; + } + + std::function add = [&](int u, int v, int w) -> void { + edges.emplace_back(v, w, head[u]); + head[u] = edges.size() - 1; + }; + + for (int i = 1, x, y; i <= m; i++) { + cin >> x >> y; + + add(i << 1, i << 1 | 1, 1); + add(i << 1 | 1, i << 1, 1); + + add(pre[x], i << 1, pre[x] ? a[x] : 1); + add(i << 1, pre[x], 0); + pre[x] = i << 1; + + add(pre[y], i << 1 | 1, pre[y] ? a[y] : 1); + add(i << 1 | 1, pre[y], 0); + pre[y] = i << 1 | 1; + } + + add(pre[1], t, a[1]); + add(t, pre[1], 0); + + std::vector dist((m + 1) << 1); + + std::function bfs = [&]() -> bool { + std::fill(dist.begin(), dist.end(), 0); + + std::queue q; + + q.emplace(s); + dist[s] = 1; + + while (!q.empty()) { + int u = q.front(); + q.pop(); + + for (int i = head[u]; ~i; i = std::get<2>(edges[i])) { + int v = std::get<0>(edges[i]), + w = std::get<1>(edges[i]); + + if (!dist[v] && w) { + dist[v] = dist[u] + 1; + + if (v == t) return true; + + q.emplace(v); + } + } + } + + return false; + }; + + std::function dinic = [&](int u, int limit) -> int { + if (u == t) return limit; + + int flow = 0; + + for (int i = head[u]; ~i; i = std::get<2>(edges[i])) { + int v = std::get<0>(edges[i]), + w = std::get<1>(edges[i]); + + if (dist[v] == dist[u] + 1 && w) { + int k = dinic(v, std::min(w, limit - flow)); + + if (!k) dist[v] = 0; + + std::get<1>(edges[i]) -= k; + std::get<1>(edges[i ^ 1]) += k; + flow += k; + } + } + + return flow; + }; + + int res = 0; + + while (bfs()) { + while (int flow = dinic(s, INF)) res += flow; + } + + cout << res << endl; + } + + return 0; +} diff --git a/S2OJ/1363/data/data1.in b/S2OJ/1363/data/data1.in new file mode 100644 index 00000000..297a5dff --- /dev/null +++ b/S2OJ/1363/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:54feff35986e15b0e9034a4cc671120abd57011f8d5cf447a461e88be831b875 +size 414 diff --git a/S2OJ/1363/data/data1.out b/S2OJ/1363/data/data1.out new file mode 100644 index 00000000..5d90f004 --- /dev/null +++ b/S2OJ/1363/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4b42fef3d5e3e7c615607bc6071ff5c0a628b0133bba913871091f25fddb4be0 +size 30 diff --git a/S2OJ/1363/data/data10.in b/S2OJ/1363/data/data10.in new file mode 100644 index 00000000..7a0ef4fb --- /dev/null +++ b/S2OJ/1363/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a8d415d06accb8445ebdce5a9c79e8ca8cc6bc6abc3efd85c415bf32439ec4a4 +size 424349 diff --git a/S2OJ/1363/data/data10.out b/S2OJ/1363/data/data10.out new file mode 100644 index 00000000..8502ccef --- /dev/null +++ b/S2OJ/1363/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4744b63a7f439a84e61374643619afb67e0648ed5faa7049a2794f8f04ba83f1 +size 50 diff --git a/S2OJ/1363/data/data2.in b/S2OJ/1363/data/data2.in new file mode 100644 index 00000000..4529fed7 --- /dev/null +++ b/S2OJ/1363/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:5ceff7fd8cde3ce6b1ccd6f20b6e0a517df43cb5ace3e28c4041bbeb576ca4fd +size 335681 diff --git a/S2OJ/1363/data/data2.out b/S2OJ/1363/data/data2.out new file mode 100644 index 00000000..e5206169 --- /dev/null +++ b/S2OJ/1363/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:f60e2b0587067cc1f74125b86adee8010e7e8f2879ad318a15e878094fa82d9b +size 50 diff --git a/S2OJ/1363/data/data3.in b/S2OJ/1363/data/data3.in new file mode 100644 index 00000000..9ef60a8f --- /dev/null +++ b/S2OJ/1363/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a496f6276e2b8af648d7d90ae8d4a51ca22f00232eedf281c8aa2e703ed126f8 +size 341140 diff --git a/S2OJ/1363/data/data3.out b/S2OJ/1363/data/data3.out new file mode 100644 index 00000000..e7f76604 --- /dev/null +++ b/S2OJ/1363/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aafe17920bb0a9af3f5f3315c760ec8b43eb4d74c4f7b70c82c0f879d2e868fd +size 50 diff --git a/S2OJ/1363/data/data4.in b/S2OJ/1363/data/data4.in new file mode 100644 index 00000000..a490de98 --- /dev/null +++ b/S2OJ/1363/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:31d3bb03ca464beec973a39ecd5390efb5e64aa805fb336f7f4c6f0f622c4e72 +size 766 diff --git a/S2OJ/1363/data/data4.out b/S2OJ/1363/data/data4.out new file mode 100644 index 00000000..8e37ac7a --- /dev/null +++ b/S2OJ/1363/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:575084c5ff1c1091abe1af2286bb9ddd9effc96c4745472c3f17908653ef72b7 +size 30 diff --git a/S2OJ/1363/data/data5.in b/S2OJ/1363/data/data5.in new file mode 100644 index 00000000..496ed19c --- /dev/null +++ b/S2OJ/1363/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:52a43d5f2f207f5d3b7cb2c860d705089425bb071c7e57e121c61c96cc163b1e +size 397148 diff --git a/S2OJ/1363/data/data5.out b/S2OJ/1363/data/data5.out new file mode 100644 index 00000000..71616bc9 --- /dev/null +++ b/S2OJ/1363/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:8ca30ff94fc7f9af330c1a7575268e7a0dc99956694f40eaab5749f2ddf8de6a +size 35 diff --git a/S2OJ/1363/data/data6.in b/S2OJ/1363/data/data6.in new file mode 100644 index 00000000..bd0d9c32 --- /dev/null +++ b/S2OJ/1363/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4a8b5c0ccd9cdd3cbea21d68bd6321d7eff1148db07360266fe3b495b48a4db8 +size 409774 diff --git a/S2OJ/1363/data/data6.out b/S2OJ/1363/data/data6.out new file mode 100644 index 00000000..97ad9b84 --- /dev/null +++ b/S2OJ/1363/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:7d460045624c362f63def0f84714cbea3d06ecdeed0340184a0edba52236b585 +size 37 diff --git a/S2OJ/1363/data/data7.in b/S2OJ/1363/data/data7.in new file mode 100644 index 00000000..176bf1c0 --- /dev/null +++ b/S2OJ/1363/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d51ecf1c2d434790f824b0041bc878b0c72797fad0f8d66119cb3786bea40428 +size 318786 diff --git a/S2OJ/1363/data/data7.out b/S2OJ/1363/data/data7.out new file mode 100644 index 00000000..19560221 --- /dev/null +++ b/S2OJ/1363/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d4a97def9dd68eeb855d1ae0c2cc5f28eeff4ba9827b37cb2c8ab08b882eb4d8 +size 40 diff --git a/S2OJ/1363/data/data8.in b/S2OJ/1363/data/data8.in new file mode 100644 index 00000000..9e4eba62 --- /dev/null +++ b/S2OJ/1363/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:99d49c9d71859d6292d03f05814ae153aedf8924d39a911883f69fbd2d7059a4 +size 21179 diff --git a/S2OJ/1363/data/data8.out b/S2OJ/1363/data/data8.out new file mode 100644 index 00000000..2a5b7f07 --- /dev/null +++ b/S2OJ/1363/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:737d27ea03dae4453c2499289670691f7c78e3b29f506b0c206b14fe2af2ff44 +size 40 diff --git a/S2OJ/1363/data/data9.in b/S2OJ/1363/data/data9.in new file mode 100644 index 00000000..7420e6b3 --- /dev/null +++ b/S2OJ/1363/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:6fb47c245c6542a415603ddd5bf68855694a573865fa24bb33be3f620d7adadf +size 16984 diff --git a/S2OJ/1363/data/data9.out b/S2OJ/1363/data/data9.out new file mode 100644 index 00000000..3e95ddef --- /dev/null +++ b/S2OJ/1363/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2e72afe709911535118c12604352e8b2f35ce88df3a58881ba13a069d3267425 +size 40 diff --git a/S2OJ/1363/data/problem.conf b/S2OJ/1363/data/problem.conf new file mode 100644 index 00000000..ba9de959 --- /dev/null +++ b/S2OJ/1363/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30571b8545311d892f94d95e21b7a5ee74e6f33bf2ec8f532fd209827fdd4be9 +size 194