Problem:
Score : 900 points

Problem Statement

Let N be an even number.

There is a tree with N vertices.
The vertices are numbered 1, 2, ..., N.
For each i (1 \leq i \leq N - 1), the i-th edge connects Vertex x_i and y_i.

Snuke would like to decorate the tree with ribbons, as follows.

First, he will divide the N vertices into N / 2 pairs.
Here, each vertex must belong to exactly one pair.
Then, for each pair (u, v), put a ribbon through all the edges contained in the shortest path between u and v.

Snuke is trying to divide the vertices into pairs so that the following condition is satisfied: "for every edge, there is at least one ribbon going through it."
How many ways are there to divide the vertices into pairs, satisfying this condition?
Find the count modulo 10^9 + 7.
Here, two ways to divide the vertices into pairs are considered different when there is a pair that is contained in one of the two ways but not in the other.

Constraints

N is an even number.

2 \leq N \leq 5000

1 \leq x_i, y_i \leq N

The given graph is a tree.

Input

Input is given from Standard Input in the following format:

N
x_1 y_1
x_2 y_2
:
x_{N - 1} y_{N - 1}

Output

Print the number of the ways to divide the vertices into pairs, satisfying the condition, modulo 10^9 + 7.

Sample Input 1

4
1 2
2 3
3 4

Sample Output 1

2

There are three possible ways to divide the vertices into pairs, as shown below, and two satisfy the condition: the middle one and the right one.

Sample Input 2

4
1 2
1 3
1 4

Sample Output 2

3

There are three possible ways to divide the vertices into pairs, as shown below, and all of them satisfy the condition.

Sample Input 3

6
1 2
1 3
3 4
1 5
5 6

Sample Output 3

10

Sample Input 4

10
8 5
10 8
6 5
1 5
4 8
2 10
3 6
9 2
1 7

Sample Output 4

672

Solution in C++ (GCC 9.2.1) (judge verdict: Accepted)

#include<bits/stdc++.h>
#define rep(i,a,b) for (int i = (a); i <= (b); ++i)
#define drep(i,a,b) for (int i = (a); i >= (b); --i)
#define grep(i,u) for (int i = head[u],v = e[i].v; i; v = e[i = e[i].nxt].v)
#define il inline
#define LL long long
#define ULL unsigned LL
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define pll pair<LL,LL>
#define fi first
#define se second
using namespace std;
il int read() {
	int res = 0,f = 1; char ch = getchar(); while (!isdigit(ch)) {if (ch == '-') f = -f; ch = getchar();}
	while (isdigit(ch)) {res = res*10+ch-'0'; ch = getchar();} return res*f;
}
namespace qiqi {
	const int N = 5005,P = 1e9+7; int n,ecnt,head[N],f[N][N],g[N],h[N],siz[N]; struct Edge {int v,nxt;} e[N<<1]; il void add(int u,int v) {e[++ecnt] = (Edge){v,head[u]}; head[u] = ecnt;}
	void dfs(int u,int fa) {
		f[u][siz[u] = 1] = 1; grep(k,u) if (v != fa) {
			dfs(v,u); rep(i,1,siz[u]) {h[i] = f[u][i]; f[u][i] = 0;}
			rep(i,0,siz[u]) rep(j,0,siz[v]) f[u][i+j] = (f[u][i+j]+1LL*h[i]*f[v][j]%P)%P; siz[u] += siz[v];
		}
		rep(i,1,siz[u]>>1) f[u][0] = (f[u][0]-1LL*f[u][i<<1]*g[i]%P)%P;
	}
	void main() {n = read(); g[0] = 1; rep(i,1,n>>1) g[i] = 1LL*(i*2-1)*g[i-1]%P; rep(i,1,n-1) {int u = read(),v = read(); add(u,v); add(v,u);} dfs(1,0); printf("%d\n",(-f[1][0]+P)%P);}
}
int main() {qiqi::main(); return 0;}