题解

if (c[i][j] && !ban[i] && !ban[j])
now += f[v][j];
(c[i][j] & !ban[i] & !ban[j]) ? now += f[v][j] : 19260817;
now += f[v][j] * (c[i][j] & !ban[i] & !ban[j]);

#include<bits/stdc++.h>
#define fo(i, a, b) for (Re int i = (a); i <= (b); ++i)
#define fd(i, a, b) for (Re int i = (a); i >= (b); --i)
#define edge(i, u) for (int i = head[u], v = e[i].v; i; i = e[i].nxt, v = e[i].v)
#define Re register
#define N 20
#define mod 1004535809
#define ll long long
#define qwq
bool c[N][N], ban[N];
ll ans;
struct edge{
int nxt, v;
}e[804];
inline void addedge (int u, int v)
{
}
ll f[N][N];
inline void dfs (int u, int fa)
{
fo (i, 1, n)
{
if (ban[i]) {f[u][i] = 0; continue;} else f[u][i] = 1;
edge (I, u)
{
if (v == fa) continue;
dfs(v, u);
ll now = 0;
fo (j, 1, n)
if (c[i][j] && !ban[i] && !ban[j])
now += f[v][j];
f[u][i] = f[u][i] * now;
}
}
}
int main()
{
#ifdef debug
freopen("in.txt", "r", stdin);
#endif
scanf("%d %d", &n, &m);
fo (i, 1, m)
{
int u, v;
scanf("%d %d", &u, &v);
c[u][v] = c[v][u] = 1;
}
fo (i, 2, n)
{
int u, v;
scanf("%d %d", &u, &v);
}
int up = (1 << n) - 1;
fo (s, 0, up)
{
int cnt = 0;
fo (i, 1, n)
if (1 << i - 1 & s)
ban[i] = 1, ++cnt;
else
ban[i] = 0;
dfs(1, 0);
ll sum = 0;
fo (i, 1, n) sum += f[1][i];
if (cnt & 1) ans -= sum; else ans += sum;
}
printf("%lld", ans);
}