From 05cda6bedfdabc74ce6e961a959fb1bc5460ec98 Mon Sep 17 00:00:00 2001 From: Baoshuo Date: Mon, 6 Feb 2023 21:12:09 +0800 Subject: [PATCH] =?UTF-8?q?#4455.=20[ZJOI2016]=20=E5=B0=8F=E6=98=9F?= =?UTF-8?q?=E6=98=9F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit https://hydro.ac/d/bzoj/record/63e0fc84dd8145683f798089 --- BZOJ/4455/4455.cpp | 85 +++++++++++++++++++++++++++++++++++++++++++ BZOJ/4455/data/1.in | 3 ++ BZOJ/4455/data/1.out | 3 ++ BZOJ/4455/data/10.in | 3 ++ BZOJ/4455/data/10.out | 3 ++ BZOJ/4455/data/2.in | 3 ++ BZOJ/4455/data/2.out | 3 ++ BZOJ/4455/data/3.in | 3 ++ BZOJ/4455/data/3.out | 3 ++ BZOJ/4455/data/4.in | 3 ++ BZOJ/4455/data/4.out | 3 ++ BZOJ/4455/data/5.in | 3 ++ BZOJ/4455/data/5.out | 3 ++ BZOJ/4455/data/6.in | 3 ++ BZOJ/4455/data/6.out | 3 ++ BZOJ/4455/data/7.in | 3 ++ BZOJ/4455/data/7.out | 3 ++ BZOJ/4455/data/8.in | 3 ++ BZOJ/4455/data/8.out | 3 ++ BZOJ/4455/data/9.in | 3 ++ BZOJ/4455/data/9.out | 3 ++ 21 files changed, 145 insertions(+) create mode 100644 BZOJ/4455/4455.cpp create mode 100644 BZOJ/4455/data/1.in create mode 100644 BZOJ/4455/data/1.out create mode 100644 BZOJ/4455/data/10.in create mode 100644 BZOJ/4455/data/10.out create mode 100644 BZOJ/4455/data/2.in create mode 100644 BZOJ/4455/data/2.out create mode 100644 BZOJ/4455/data/3.in create mode 100644 BZOJ/4455/data/3.out create mode 100644 BZOJ/4455/data/4.in create mode 100644 BZOJ/4455/data/4.out create mode 100644 BZOJ/4455/data/5.in create mode 100644 BZOJ/4455/data/5.out create mode 100644 BZOJ/4455/data/6.in create mode 100644 BZOJ/4455/data/6.out create mode 100644 BZOJ/4455/data/7.in create mode 100644 BZOJ/4455/data/7.out create mode 100644 BZOJ/4455/data/8.in create mode 100644 BZOJ/4455/data/8.out create mode 100644 BZOJ/4455/data/9.in create mode 100644 BZOJ/4455/data/9.out diff --git a/BZOJ/4455/4455.cpp b/BZOJ/4455/4455.cpp new file mode 100644 index 00000000..84dc712f --- /dev/null +++ b/BZOJ/4455/4455.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/BZOJ/4455/data/1.in b/BZOJ/4455/data/1.in new file mode 100644 index 00000000..d94ad046 --- /dev/null +++ b/BZOJ/4455/data/1.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:090eb54d7253a3de4e605ebb663e6df2a73d300a9c27eb627586df641c8d6e14 +size 619 diff --git a/BZOJ/4455/data/1.out b/BZOJ/4455/data/1.out new file mode 100644 index 00000000..f59cde8e --- /dev/null +++ b/BZOJ/4455/data/1.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:cb2a38af1140a869f23ddd992b2847bb712c2f5f2cf9a7f61932bf743bf4f050 +size 14 diff --git a/BZOJ/4455/data/10.in b/BZOJ/4455/data/10.in new file mode 100644 index 00000000..7d80f4b6 --- /dev/null +++ b/BZOJ/4455/data/10.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e76fda44d4570fc69f77bc257c3ab440eea4692db4726db93508e1288ee0c8 +size 441 diff --git a/BZOJ/4455/data/10.out b/BZOJ/4455/data/10.out new file mode 100644 index 00000000..ff252e96 --- /dev/null +++ b/BZOJ/4455/data/10.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:9163a8be8bb2add0f440542062d728baee09a657b57a205fe1497e137a49c669 +size 11 diff --git a/BZOJ/4455/data/2.in b/BZOJ/4455/data/2.in new file mode 100644 index 00000000..b048c35c --- /dev/null +++ b/BZOJ/4455/data/2.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:d69f8a6eb464cefaaa4e250a5ef6b43ebffa7a31569b0b366be150b37f328f89 +size 280 diff --git a/BZOJ/4455/data/2.out b/BZOJ/4455/data/2.out new file mode 100644 index 00000000..f15c54be --- /dev/null +++ b/BZOJ/4455/data/2.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:e84f4f0c21594d02c27a7fa1a3a50031e69af956b091f7962cfabdc0f2db4a54 +size 6 diff --git a/BZOJ/4455/data/3.in b/BZOJ/4455/data/3.in new file mode 100644 index 00000000..93d7709b --- /dev/null +++ b/BZOJ/4455/data/3.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1d0fbf751a57d2b6d102a87ee86498a6dec94a11d76217367b8ddabdac05c7a8 +size 444 diff --git a/BZOJ/4455/data/3.out b/BZOJ/4455/data/3.out new file mode 100644 index 00000000..2fcade90 --- /dev/null +++ b/BZOJ/4455/data/3.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:2cfcdfe7bca156661d54481b261b81bea0c5e6bc1498b187175a3f5978e514a9 +size 11 diff --git a/BZOJ/4455/data/4.in b/BZOJ/4455/data/4.in new file mode 100644 index 00000000..86b1d77b --- /dev/null +++ b/BZOJ/4455/data/4.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:fba7beba37f128bf3af8c731710cc678efc2f1d8ff4bab17a1abadb73ec5df03 +size 623 diff --git a/BZOJ/4455/data/4.out b/BZOJ/4455/data/4.out new file mode 100644 index 00000000..2dc062b0 --- /dev/null +++ b/BZOJ/4455/data/4.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a2e5215c5d9866f56af69d67c45cc448cb34a553fe1b44fa6e0659f4e7a510a1 +size 14 diff --git a/BZOJ/4455/data/5.in b/BZOJ/4455/data/5.in new file mode 100644 index 00000000..67921dd5 --- /dev/null +++ b/BZOJ/4455/data/5.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:4e2708d7a7767ce16480a66fdd72761cccfa49766096a40fac29ab21e104b105 +size 384 diff --git a/BZOJ/4455/data/5.out b/BZOJ/4455/data/5.out new file mode 100644 index 00000000..f2e95cb8 --- /dev/null +++ b/BZOJ/4455/data/5.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:3e92185c03df3a92cb09fcee4937e9e10089a30b3d4918a69bd485af097e65ac +size 11 diff --git a/BZOJ/4455/data/6.in b/BZOJ/4455/data/6.in new file mode 100644 index 00000000..5ffae0f5 --- /dev/null +++ b/BZOJ/4455/data/6.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:1b55696a9587bafa208315587316f659c2c47ab3b2d6a10c9e0cf083791e2063 +size 348 diff --git a/BZOJ/4455/data/6.out b/BZOJ/4455/data/6.out new file mode 100644 index 00000000..e6da7551 --- /dev/null +++ b/BZOJ/4455/data/6.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:c6e12032ee0ffe83f4369e3980a0ded1543e6d99530a0d86c58fc0d6d87a4125 +size 10 diff --git a/BZOJ/4455/data/7.in b/BZOJ/4455/data/7.in new file mode 100644 index 00000000..5b8fdca5 --- /dev/null +++ b/BZOJ/4455/data/7.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b0ea96650780c4ad14800aace554e7a0516997f0a08a6a507742ecd4f1c49c40 +size 478 diff --git a/BZOJ/4455/data/7.out b/BZOJ/4455/data/7.out new file mode 100644 index 00000000..6ff0c7a7 --- /dev/null +++ b/BZOJ/4455/data/7.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:58fbd6552c99a2ab7c4c65f8fc0ea42619c363085b9c8ef7aca98ce65f7343da +size 12 diff --git a/BZOJ/4455/data/8.in b/BZOJ/4455/data/8.in new file mode 100644 index 00000000..39d68382 --- /dev/null +++ b/BZOJ/4455/data/8.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:34feda06ba3ba5f49b75b221b0e677ebcdda0ae9bbf31e3a13e2faabdde3c2a7 +size 123 diff --git a/BZOJ/4455/data/8.out b/BZOJ/4455/data/8.out new file mode 100644 index 00000000..d748984a --- /dev/null +++ b/BZOJ/4455/data/8.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:a4b3116b2c9879d49feca51c192ebaf0415d79d7b915f5e6db1e75153d63cda9 +size 4 diff --git a/BZOJ/4455/data/9.in b/BZOJ/4455/data/9.in new file mode 100644 index 00000000..426645bc --- /dev/null +++ b/BZOJ/4455/data/9.in @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:b893024b8482226ade4be88ab4e7c2f8ddbe7a052ec155b188cbe5fa3d74518f +size 182 diff --git a/BZOJ/4455/data/9.out b/BZOJ/4455/data/9.out new file mode 100644 index 00000000..2c9a6988 --- /dev/null +++ b/BZOJ/4455/data/9.out @@ -0,0 +1,3 @@ +version https://git-lfs.github.com/spec/v1 +oid sha256:bc5411893eb38f88ed1597d24ff8bef9f957db2c1facfb37ba3a78630cfa6210 +size 6