From 350f5cab8e55dd586b5a098115cbf2f8fe05fb01 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Feb 2023 21:07:24 +0800 Subject: [PATCH] =?UTF-8?q?#1897.=20=E3=80=90ZJOI2016=E3=80=91=E5=B0=8F?= =?UTF-8?q?=E6=98=9F=E6=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://sjzezoj.com/submission/68129 --- S2OJ/1897/1897.cpp | 85 +++++++++++++++++++++++++++++++++++++ S2OJ/1897/data/data1.in | 3 ++ S2OJ/1897/data/data1.out | 3 ++ S2OJ/1897/data/data10.in | 3 ++ S2OJ/1897/data/data10.out | 3 ++ S2OJ/1897/data/data2.in | 3 ++ S2OJ/1897/data/data2.out | 3 ++ S2OJ/1897/data/data3.in | 3 ++ S2OJ/1897/data/data3.out | 3 ++ S2OJ/1897/data/data4.in | 3 ++ S2OJ/1897/data/data4.out | 3 ++ S2OJ/1897/data/data5.in | 3 ++ S2OJ/1897/data/data5.out | 3 ++ S2OJ/1897/data/data6.in | 3 ++ S2OJ/1897/data/data6.out | 3 ++ S2OJ/1897/data/data7.in | 3 ++ S2OJ/1897/data/data7.out | 3 ++ S2OJ/1897/data/data8.in | 3 ++ S2OJ/1897/data/data8.out | 3 ++ S2OJ/1897/data/data9.in | 3 ++ S2OJ/1897/data/data9.out | 3 ++ S2OJ/1897/data/problem.conf | 3 ++ 22 files changed, 148 insertions(+) create mode 100644 S2OJ/1897/1897.cpp create mode 100644 S2OJ/1897/data/data1.in create mode 100644 S2OJ/1897/data/data1.out create mode 100644 S2OJ/1897/data/data10.in create mode 100644 S2OJ/1897/data/data10.out create mode 100644 S2OJ/1897/data/data2.in create mode 100644 S2OJ/1897/data/data2.out create mode 100644 S2OJ/1897/data/data3.in create mode 100644 S2OJ/1897/data/data3.out create mode 100644 S2OJ/1897/data/data4.in create mode 100644 S2OJ/1897/data/data4.out create mode 100644 S2OJ/1897/data/data5.in create mode 100644 S2OJ/1897/data/data5.out create mode 100644 S2OJ/1897/data/data6.in create mode 100644 S2OJ/1897/data/data6.out create mode 100644 S2OJ/1897/data/data7.in create mode 100644 S2OJ/1897/data/data7.out create mode 100644 S2OJ/1897/data/data8.in create mode 100644 S2OJ/1897/data/data8.out create mode 100644 S2OJ/1897/data/data9.in create mode 100644 S2OJ/1897/data/data9.out create mode 100644 S2OJ/1897/data/problem.conf diff --git a/S2OJ/1897/1897.cpp b/S2OJ/1897/1897.cpp new file mode 100644 index 00000000..84dc712f --- /dev/null +++ b/S2OJ/1897/1897.cpp @@ -0,0 +1,85 @@ +#include +#include +#include + +using std::cin; +using std::cout; +const char endl = '\n'; + +const int N = 20; + +int n, m; +long long f[N][N], ans; +bool map[N][N], vis[N]; +std::vector g[N]; + +void dfs(int u, int fa) { + for (int i = 1; i <= n; i++) { + if (vis[i]) f[u][i] = 1; + } + + for (int v : g[u]) { + if (v == fa) continue; + + dfs(v, u); + + for (int i = 1; i <= n; i++) { + if (!vis[i]) continue; + + long long t = f[u][i]; + + for (int j = 1; j <= n; j++) { + if (!vis[j] || !map[i][j]) continue; + + f[u][i] += t * f[v][j]; + } + } + } +} + +int main() { + std::ios::sync_with_stdio(false); + cin.tie(nullptr); + + cin >> n >> m; + + for (int i = 1, u, v; i <= m; i++) { + cin >> u >> v; + + map[u][v] = map[v][u] = true; + } + + for (int i = 1, u, v; i < n; i++) { + cin >> u >> v; + + g[u].emplace_back(v); + g[v].emplace_back(u); + } + + for (int s = 0; s < 1 << n; s++) { + memset(f, 0x00, sizeof(f)); + memset(vis, 0x00, sizeof(vis)); + + for (int i = 1; i <= n; i++) { + if ((s >> (i - 1)) & 1) vis[i] = true; + } + + dfs(1, -1); + + long long sum = 0; + + for (int i = 1; i <= n; i++) { + sum += f[1][i]; + } + + if ((n - __builtin_popcount(s)) & 1) { + ans -= sum; + } else { + ans += sum; + } + } + + cout << ans << endl; + + return 0; +} diff --git a/S2OJ/1897/data/data1.in b/S2OJ/1897/data/data1.in new file mode 100644 index 00000000..d94ad046 --- /dev/null +++ b/S2OJ/1897/data/data1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:090eb54d7253a3de4e605ebb663e6df2a73d300a9c27eb627586df641c8d6e14 +size 619 diff --git a/S2OJ/1897/data/data1.out b/S2OJ/1897/data/data1.out new file mode 100644 index 00000000..f59cde8e --- /dev/null +++ b/S2OJ/1897/data/data1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb2a38af1140a869f23ddd992b2847bb712c2f5f2cf9a7f61932bf743bf4f050 +size 14 diff --git a/S2OJ/1897/data/data10.in b/S2OJ/1897/data/data10.in new file mode 100644 index 00000000..7d80f4b6 --- /dev/null +++ b/S2OJ/1897/data/data10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e76fda44d4570fc69f77bc257c3ab440eea4692db4726db93508e1288ee0c8 +size 441 diff --git a/S2OJ/1897/data/data10.out b/S2OJ/1897/data/data10.out new file mode 100644 index 00000000..ff252e96 --- /dev/null +++ b/S2OJ/1897/data/data10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9163a8be8bb2add0f440542062d728baee09a657b57a205fe1497e137a49c669 +size 11 diff --git a/S2OJ/1897/data/data2.in b/S2OJ/1897/data/data2.in new file mode 100644 index 00000000..b048c35c --- /dev/null +++ b/S2OJ/1897/data/data2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d69f8a6eb464cefaaa4e250a5ef6b43ebffa7a31569b0b366be150b37f328f89 +size 280 diff --git a/S2OJ/1897/data/data2.out b/S2OJ/1897/data/data2.out new file mode 100644 index 00000000..f15c54be --- /dev/null +++ b/S2OJ/1897/data/data2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e84f4f0c21594d02c27a7fa1a3a50031e69af956b091f7962cfabdc0f2db4a54 +size 6 diff --git a/S2OJ/1897/data/data3.in b/S2OJ/1897/data/data3.in new file mode 100644 index 00000000..93d7709b --- /dev/null +++ b/S2OJ/1897/data/data3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d0fbf751a57d2b6d102a87ee86498a6dec94a11d76217367b8ddabdac05c7a8 +size 444 diff --git a/S2OJ/1897/data/data3.out b/S2OJ/1897/data/data3.out new file mode 100644 index 00000000..2fcade90 --- /dev/null +++ b/S2OJ/1897/data/data3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2cfcdfe7bca156661d54481b261b81bea0c5e6bc1498b187175a3f5978e514a9 +size 11 diff --git a/S2OJ/1897/data/data4.in b/S2OJ/1897/data/data4.in new file mode 100644 index 00000000..86b1d77b --- /dev/null +++ b/S2OJ/1897/data/data4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fba7beba37f128bf3af8c731710cc678efc2f1d8ff4bab17a1abadb73ec5df03 +size 623 diff --git a/S2OJ/1897/data/data4.out b/S2OJ/1897/data/data4.out new file mode 100644 index 00000000..2dc062b0 --- /dev/null +++ b/S2OJ/1897/data/data4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2e5215c5d9866f56af69d67c45cc448cb34a553fe1b44fa6e0659f4e7a510a1 +size 14 diff --git a/S2OJ/1897/data/data5.in b/S2OJ/1897/data/data5.in new file mode 100644 index 00000000..67921dd5 --- /dev/null +++ b/S2OJ/1897/data/data5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e2708d7a7767ce16480a66fdd72761cccfa49766096a40fac29ab21e104b105 +size 384 diff --git a/S2OJ/1897/data/data5.out b/S2OJ/1897/data/data5.out new file mode 100644 index 00000000..f2e95cb8 --- /dev/null +++ b/S2OJ/1897/data/data5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e92185c03df3a92cb09fcee4937e9e10089a30b3d4918a69bd485af097e65ac +size 11 diff --git a/S2OJ/1897/data/data6.in b/S2OJ/1897/data/data6.in new file mode 100644 index 00000000..5ffae0f5 --- /dev/null +++ b/S2OJ/1897/data/data6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b55696a9587bafa208315587316f659c2c47ab3b2d6a10c9e0cf083791e2063 +size 348 diff --git a/S2OJ/1897/data/data6.out b/S2OJ/1897/data/data6.out new file mode 100644 index 00000000..e6da7551 --- /dev/null +++ b/S2OJ/1897/data/data6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e12032ee0ffe83f4369e3980a0ded1543e6d99530a0d86c58fc0d6d87a4125 +size 10 diff --git a/S2OJ/1897/data/data7.in b/S2OJ/1897/data/data7.in new file mode 100644 index 00000000..5b8fdca5 --- /dev/null +++ b/S2OJ/1897/data/data7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0ea96650780c4ad14800aace554e7a0516997f0a08a6a507742ecd4f1c49c40 +size 478 diff --git a/S2OJ/1897/data/data7.out b/S2OJ/1897/data/data7.out new file mode 100644 index 00000000..6ff0c7a7 --- /dev/null +++ b/S2OJ/1897/data/data7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58fbd6552c99a2ab7c4c65f8fc0ea42619c363085b9c8ef7aca98ce65f7343da +size 12 diff --git a/S2OJ/1897/data/data8.in b/S2OJ/1897/data/data8.in new file mode 100644 index 00000000..39d68382 --- /dev/null +++ b/S2OJ/1897/data/data8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34feda06ba3ba5f49b75b221b0e677ebcdda0ae9bbf31e3a13e2faabdde3c2a7 +size 123 diff --git a/S2OJ/1897/data/data8.out b/S2OJ/1897/data/data8.out new file mode 100644 index 00000000..d748984a --- /dev/null +++ b/S2OJ/1897/data/data8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4b3116b2c9879d49feca51c192ebaf0415d79d7b915f5e6db1e75153d63cda9 +size 4 diff --git a/S2OJ/1897/data/data9.in b/S2OJ/1897/data/data9.in new file mode 100644 index 00000000..426645bc --- /dev/null +++ b/S2OJ/1897/data/data9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b893024b8482226ade4be88ab4e7c2f8ddbe7a052ec155b188cbe5fa3d74518f +size 182 diff --git a/S2OJ/1897/data/data9.out b/S2OJ/1897/data/data9.out new file mode 100644 index 00000000..2c9a6988 --- /dev/null +++ b/S2OJ/1897/data/data9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc5411893eb38f88ed1597d24ff8bef9f957db2c1facfb37ba3a78630cfa6210 +size 6 diff --git a/S2OJ/1897/data/problem.conf b/S2OJ/1897/data/problem.conf new file mode 100644 index 00000000..bfa99af8 --- /dev/null +++ b/S2OJ/1897/data/problem.conf @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:14af6f937e7343ed6065b7f1ae40f21cb514266e9af9ad52c51237646b759e35 +size 208