mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-12-24 18:11:59 +00:00
parent
2f74725305
commit
350f5cab8e
85
S2OJ/1897/1897.cpp
Normal file
85
S2OJ/1897/1897.cpp
Normal 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
S2OJ/1897/data/data1.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data1.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data1.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data1.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data10.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data10.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data10.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data10.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data2.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data2.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data2.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data2.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data3.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data3.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data3.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data3.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data4.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data4.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data4.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data4.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data5.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data5.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data5.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data5.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data6.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data6.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data6.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data6.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data7.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data7.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data7.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data7.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data8.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data8.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data8.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data8.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data9.in
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data9.in
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/data9.out
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/data9.out
(Stored with Git LFS)
Normal file
Binary file not shown.
BIN
S2OJ/1897/data/problem.conf
(Stored with Git LFS)
Normal file
BIN
S2OJ/1897/data/problem.conf
(Stored with Git LFS)
Normal file
Binary file not shown.
Loading…
Reference in New Issue
Block a user