From e03f98b65ef9c84477d32c342b79d130be39436d Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 5 Dec 2022 20:15:31 +0800 Subject: [PATCH] =?UTF-8?q?#1788.=20=E3=80=902017.3=E9=95=BF=E4=B9=90?= =?UTF-8?q?=E7=9C=81=E9=80=89=E9=9B=86=E8=AE=ADDay8T3=E3=80=91=E4=BF=AE?= =?UTF-8?q?=E8=B7=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/65457 --- S2OJ/1788/1788.cpp | 105 ++++++++++++++++++++++++++++++++++++ S2OJ/1788/data/problem.conf | 3 ++ S2OJ/1788/data/road1.in | 3 ++ S2OJ/1788/data/road1.out | 3 ++ S2OJ/1788/data/road10.in | 3 ++ S2OJ/1788/data/road10.out | 3 ++ S2OJ/1788/data/road2.in | 3 ++ S2OJ/1788/data/road2.out | 3 ++ S2OJ/1788/data/road3.in | 3 ++ S2OJ/1788/data/road3.out | 3 ++ S2OJ/1788/data/road4.in | 3 ++ S2OJ/1788/data/road4.out | 3 ++ S2OJ/1788/data/road5.in | 3 ++ S2OJ/1788/data/road5.out | 3 ++ S2OJ/1788/data/road6.in | 3 ++ S2OJ/1788/data/road6.out | 3 ++ S2OJ/1788/data/road7.in | 3 ++ S2OJ/1788/data/road7.out | 3 ++ S2OJ/1788/data/road8.in | 3 ++ S2OJ/1788/data/road8.out | 3 ++ S2OJ/1788/data/road9.in | 3 ++ S2OJ/1788/data/road9.out | 3 ++ 22 files changed, 168 insertions(+) create mode 100644 S2OJ/1788/1788.cpp create mode 100644 S2OJ/1788/data/problem.conf create mode 100644 S2OJ/1788/data/road1.in create mode 100644 S2OJ/1788/data/road1.out create mode 100644 S2OJ/1788/data/road10.in create mode 100644 S2OJ/1788/data/road10.out create mode 100644 S2OJ/1788/data/road2.in create mode 100644 S2OJ/1788/data/road2.out create mode 100644 S2OJ/1788/data/road3.in create mode 100644 S2OJ/1788/data/road3.out create mode 100644 S2OJ/1788/data/road4.in create mode 100644 S2OJ/1788/data/road4.out create mode 100644 S2OJ/1788/data/road5.in create mode 100644 S2OJ/1788/data/road5.out create mode 100644 S2OJ/1788/data/road6.in create mode 100644 S2OJ/1788/data/road6.out create mode 100644 S2OJ/1788/data/road7.in create mode 100644 S2OJ/1788/data/road7.out create mode 100644 S2OJ/1788/data/road8.in create mode 100644 S2OJ/1788/data/road8.out create mode 100644 S2OJ/1788/data/road9.in create mode 100644 S2OJ/1788/data/road9.out diff --git a/S2OJ/1788/1788.cpp b/S2OJ/1788/1788.cpp new file mode 100644 index 00000000..675e2f29 --- /dev/null +++ b/S2OJ/1788/1788.cpp @@ -0,0 +1,105 @@ +#include +#include +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 1e4 + 5, + K = 11; +const int INF = 0x3f3f3f3f; + +int n, m, d, f[1 << K][N], f1[1 << K]; +std::vector> g[N]; + +int steiner(int s) { + int k = 0; + + memset(f, 0x3f, sizeof(f)); + + for (int i = 1; i <= d; i++) { + std::queue q; + + if (s & (1 << (i - 1))) { + f[1 << k++][i] = 0; + f[1 << k++][n - i + 1] = 0; + } + } + + for (int s = 0; s < 1 << k; s++) { + std::queue q; + std::vector vis(n + 1); + + for (int i = 1; i <= n; i++) { + for (int t = s & (s - 1); t; t = (t - 1) & s) { + f[s][i] = std::min(f[s][i], f[t][i] + f[s ^ t][i]); + } + + if (f[s][i] != INF) { + q.emplace(i); + vis[i] = true; + } + } + + // SPFA + while (!q.empty()) { + int u = q.front(); + q.pop(); + + vis[u] = false; + + for (auto e : g[u]) { + int v = e.first, + w = e.second; + + if (f[s][v] > f[s][u] + w) { + f[s][v] = f[s][u] + w; + + if (!vis[v]) { + q.emplace(v); + vis[v] = true; + } + } + } + } + } + + int res = INF; + + for (int i = 1; i <= n; i++) { + res = std::min(res, f[(1 << k) - 1][i]); + } + + return res; +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m >> d; + + for (int i = 1, u, v, w; i <= m; i++) { + cin >> u >> v >> w; + + g[u].emplace_back(v, w); + g[v].emplace_back(u, w); + } + + memset(f1, 0x3f, sizeof(f1)); + + f1[0] = 0; + + for (int s = 1; s < 1 << d; s++) { + for (int t = s; t; t = (t - 1) & s) { + f1[s] = std::min(f1[s], f1[s ^ t] + steiner(t)); + } + } + + cout << (f1[(1 << d) - 1] == INF ? -1 : f1[(1 << d) - 1]) << endl; + + return 0; +} diff --git a/S2OJ/1788/data/problem.conf b/S2OJ/1788/data/problem.conf new file mode 100644 index 00000000..2ec29bce --- /dev/null +++ b/S2OJ/1788/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:0a4bb845b09fdb8b0bbb04aa3c8a5938c8d74c7fb802a88178c38d1af1fff9b5 +size 179 diff --git a/S2OJ/1788/data/road1.in b/S2OJ/1788/data/road1.in new file mode 100644 index 00000000..02ef9315 --- /dev/null +++ b/S2OJ/1788/data/road1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c74198c5387639d3849d0043c4cb8f1c19692298a74178f35005578c79751d22 +size 136 diff --git a/S2OJ/1788/data/road1.out b/S2OJ/1788/data/road1.out new file mode 100644 index 00000000..06d04c2c --- /dev/null +++ b/S2OJ/1788/data/road1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:aa67a169b0bba217aa0aa88a65346920c84c42447c36ba5f7ea65f422c1fe5d8 +size 2 diff --git a/S2OJ/1788/data/road10.in b/S2OJ/1788/data/road10.in new file mode 100644 index 00000000..1e8479e2 --- /dev/null +++ b/S2OJ/1788/data/road10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b30b5527099d69479a5159908ff2c769a1c5c80f9abd7249937e75137f64f07b +size 135521 diff --git a/S2OJ/1788/data/road10.out b/S2OJ/1788/data/road10.out new file mode 100644 index 00000000..5107d3af --- /dev/null +++ b/S2OJ/1788/data/road10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e4e99b4db13242af68fa8ceef6e55ce95fad8503a0ac1defabecfd84812c9a1b +size 6 diff --git a/S2OJ/1788/data/road2.in b/S2OJ/1788/data/road2.in new file mode 100644 index 00000000..12287d80 --- /dev/null +++ b/S2OJ/1788/data/road2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:995291025851c4dd44be005ad90e61ef94039bd5b5a2927702af4691f6253801 +size 132 diff --git a/S2OJ/1788/data/road2.out b/S2OJ/1788/data/road2.out new file mode 100644 index 00000000..396b6814 --- /dev/null +++ b/S2OJ/1788/data/road2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a1fb50e6c86fae1679ef3351296fd6713411a08cf8dd1790a4fd05fae8688164 +size 3 diff --git a/S2OJ/1788/data/road3.in b/S2OJ/1788/data/road3.in new file mode 100644 index 00000000..91900ecd --- /dev/null +++ b/S2OJ/1788/data/road3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1912e2252ae3786eeecf3ac681c6c6954927d6c1aab92f4e6ef7f7274e494b65 +size 9706 diff --git a/S2OJ/1788/data/road3.out b/S2OJ/1788/data/road3.out new file mode 100644 index 00000000..0c381915 --- /dev/null +++ b/S2OJ/1788/data/road3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:13bf8b0303fde3792881f560001cd88db2d12c8d9dd78c1413acf6846d686adc +size 4 diff --git a/S2OJ/1788/data/road4.in b/S2OJ/1788/data/road4.in new file mode 100644 index 00000000..cedf5239 --- /dev/null +++ b/S2OJ/1788/data/road4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69cc72ffcac1af62df959b72d225e1e41324d3cd91f7ba897eebd93458f13c01 +size 9746 diff --git a/S2OJ/1788/data/road4.out b/S2OJ/1788/data/road4.out new file mode 100644 index 00000000..ba4dd0d6 --- /dev/null +++ b/S2OJ/1788/data/road4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee3ddb7cc831f149b0acaa8fc48d3872abef4bcf5f4f2e5b832cab797cb09330 +size 4 diff --git a/S2OJ/1788/data/road5.in b/S2OJ/1788/data/road5.in new file mode 100644 index 00000000..632e53f8 --- /dev/null +++ b/S2OJ/1788/data/road5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:08a416b97b4273b99934dbe4783dd905f3ca8d6d221d5e9cd85393916508a9a7 +size 11161 diff --git a/S2OJ/1788/data/road5.out b/S2OJ/1788/data/road5.out new file mode 100644 index 00000000..4a3c4217 --- /dev/null +++ b/S2OJ/1788/data/road5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3b0f7fb8356304ab36bfd593e40eb9e0dc42ed7bafb23723d561677544105855 +size 5 diff --git a/S2OJ/1788/data/road6.in b/S2OJ/1788/data/road6.in new file mode 100644 index 00000000..f8cefc45 --- /dev/null +++ b/S2OJ/1788/data/road6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:dfa6ead5ebf8f271ebe869b83458248216e5c6539f9a77d73ab2d371811150d0 +size 11596 diff --git a/S2OJ/1788/data/road6.out b/S2OJ/1788/data/road6.out new file mode 100644 index 00000000..c5db5693 --- /dev/null +++ b/S2OJ/1788/data/road6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:30785815905574fd36aa95b44f8562fd16a9a9d5ac3cfdd38e4134a1b52f0245 +size 5 diff --git a/S2OJ/1788/data/road7.in b/S2OJ/1788/data/road7.in new file mode 100644 index 00000000..d476028f --- /dev/null +++ b/S2OJ/1788/data/road7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:69344df0a57c2e5ec2c942ced2cc728284a83f2b60d08ab994df0f20dbc81820 +size 11702 diff --git a/S2OJ/1788/data/road7.out b/S2OJ/1788/data/road7.out new file mode 100644 index 00000000..311c4506 --- /dev/null +++ b/S2OJ/1788/data/road7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:ee3aa64bb94a50845d5024cd4bd20202a4567aed5cd5328c0d97e9920775fc28 +size 3 diff --git a/S2OJ/1788/data/road8.in b/S2OJ/1788/data/road8.in new file mode 100644 index 00000000..f78ea403 --- /dev/null +++ b/S2OJ/1788/data/road8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d18678123e29a0092e690683bf6d66afd6d2f046c13de80665506c19b7c5c6e3 +size 135486 diff --git a/S2OJ/1788/data/road8.out b/S2OJ/1788/data/road8.out new file mode 100644 index 00000000..8443c363 --- /dev/null +++ b/S2OJ/1788/data/road8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c98875846286b5e3a32baffd64764791bbd5ea289506418bf3b2e00012a7aa62 +size 6 diff --git a/S2OJ/1788/data/road9.in b/S2OJ/1788/data/road9.in new file mode 100644 index 00000000..e234d306 --- /dev/null +++ b/S2OJ/1788/data/road9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2427886bbefecaf9b0d5f52ee7732325033d26a0f0842e12ef27a1674d02b09f +size 135559 diff --git a/S2OJ/1788/data/road9.out b/S2OJ/1788/data/road9.out new file mode 100644 index 00000000..da858e35 --- /dev/null +++ b/S2OJ/1788/data/road9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e88aa5626e8caccdf9062bdafac7070f4f3b064dfc6272aa61144fadc0669289 +size 6