#include <bits/stdc++.h>
#define xx first
#define yy second
#define mp make_pair
#define pb push_back
#define fill(x, y) memset(x, y, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
using namespace std;

typedef long long LL;
typedef pair < int, int > pa;

inline int read()
{
	int sc = 0, f = 1; char ch = getchar();
	while (ch < '0' || ch > '9') { if (ch == '-') f = -1; ch = getchar(); }
	while (ch >= '0' && ch <= '9') sc = sc * 10 + ch - '0', ch = getchar();
	return sc * f;
}

const int MAXN = 1005;
const int mod = 1e9 + 7;

int n, dep[MAXN], fa[MAXN], S, T, dia, cg, cg2, f[MAXN][MAXN], ans;
vector < int > G[MAXN];

inline void inc(int &x, int y) { x += y; if (x >= mod) x -= mod; }
inline void dec(int &x, int y) { x -= y; if (x < 0) x += mod; }

inline void dfs(int x, int d)
{
	dep[x] = d;
	for (auto y : G[x]) if (y ^ fa[x]) fa[y] = x, dfs(y, d + 1);
}

inline void find_dia()
{
	dfs(1, 0);
	fill(fa, 0);
	for (int i = 1; i <= n; i ++) if (dep[i] > dep[S]) S = i;
	dfs(S, 0);
	for (int i = 1; i <= n; i ++) if (dep[i] > dep[T]) T = i;
	dia = dep[cg = T];
	for (int i = 1; i <= dep[T] >> 1; i ++) cg = fa[cg];
	if (dep[T] & 1) cg2 = fa[cg];
}

inline void dp(int x, int fa, int dep, int len)
{
	for (auto y : G[x]) if (y ^ fa) dp(y, x, dep + 1, len);
	for (int i = dep - len; i <= len - dep; i ++)
	{
		f[x][i + 502] = 1;
		for (auto y : G[x]) if (y ^ fa) f[x][i + 502] = 1LL * f[x][i + 502] * (f[y][i + 1 + 502] + f[y][i - 1 + 502]) % mod;
	}
}

int main()
{
#ifdef wxh010910
	freopen("data.in", "r", stdin);
#endif
	n = read();
	for (int i = 1, x, y; i < n; i ++) x = read(), y = read(), G[x].pb(y), G[y].pb(x);
	find_dia();
	if (dia & 1)
	{
		dp(cg, cg2, 0, dia >> 1); dp(cg2, cg, 0, dia + 1 >> 1);
		for (int i = - (dia >> 1); i <= (dia >> 1); i ++) inc(ans, 1LL * f[cg][i + 502] * (f[cg2][i + 1 + 502] + f[cg2][i - 1 + 502]) % mod);
		fill(f, 0);
		dp(cg, cg2, 0, dia + 1 >> 1); dp(cg2, cg, 0, dia >> 1);
		for (int i = - (dia >> 1); i <= (dia >> 1); i ++) inc(ans, 1LL * f[cg2][i + 502] * (f[cg][i + 1 + 502] + f[cg][i - 1 + 502]) % mod);
		fill(f, 0);
		dp(cg, cg2, 0, dia >> 1); dp(cg2, cg, 0, dia >> 1);
		for (int i = - (dia >> 1); i <= (dia >> 1); i ++) dec(ans, 2LL * f[cg][i + 502] * f[cg2][i + 502] % mod);
		for (int i = - (dia >> 1); i <= (dia >> 1); i ++) dec(ans, 1LL * f[cg][i + 502] * f[cg2][i + 2 + 502] % mod);
		for (int i = - (dia >> 1); i <= (dia >> 1); i ++) dec(ans, 1LL * f[cg][i + 502] * f[cg2][i - 2 + 502] % mod);
		return printf("%d\n", ans), 0;
	}
	else
	{
		dp(cg, 0, 0, dia >> 1);
		for (int i = - (dia >> 1); i <= (dia >> 1); i ++) inc(ans, f[cg][i + 502]);
		return printf("%d\n", ans), 0;
	}
}
