0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:16:26 +00:00

#4455. [ZJOI2016] 小星星

https://hydro.ac/d/bzoj/record/63e0fc84dd8145683f798089
This commit is contained in:
Baoshuo Ren 2023-02-06 21:12:09 +08:00
parent 350f5cab8e
commit 05cda6bedf
Signed by: baoshuo
GPG Key ID: 00CB9680AB29F51A
21 changed files with 145 additions and 0 deletions

85
BZOJ/4455/4455.cpp Normal file
View File

@ -0,0 +1,85 @@
#include <iostream>
#include <cstring>
#include <vector>
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<int> 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;
}

BIN
BZOJ/4455/data/1.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/1.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/10.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/10.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/2.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/2.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/3.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/3.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/4.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/4.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/5.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/5.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/6.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/6.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/7.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/7.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/8.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/8.out (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/9.in (Stored with Git LFS) Normal file

Binary file not shown.

BIN
BZOJ/4455/data/9.out (Stored with Git LFS) Normal file

Binary file not shown.