#include <bits/stdc++.h>
inline int in() {
  int k = 0;
  char ch = getchar();
  bool p = 1;
  while (ch < '-') ch = getchar();
  if (ch == '-') ch = getchar(), p = 0;
  while (ch > '-') k = k * 10 + ch - '0', ch = getchar();
  return p ? k : -k;
}
const int N = 2e5 + 5, YL = 1e9 + 7;
std::vector<int> G[N];
int ch[N][3], d[N], g[N], f[N], siz[N];
inline int MO(const int &x) { return x >= YL ? x - YL : x; }
inline void add(int &x, int y) {
  if ((x += y) >= YL) x -= YL;
}
int F(int x);
int F2(int x, int y);
int F(int x) {
  if (!x) return 1;
  if (siz[x] & 1) return 0;
  if (!g[x]) return siz[x] / 2;
  if (~f[x]) return f[x];
  int ans = 0, y = g[x], dx = d[x], lc = ch[y][0], rc = ch[y][1];
  for (int i = 0; i <= 1; ++i, std::swap(lc, rc)) {
    if (!ch[rc][1]) {
      if (ch[rc][0]) add(ans, F2(lc, ch[rc][0]));
      if (!g[rc] && d[rc] <= dx) add(ans, MO(F(lc) * (1 + (dx != d[rc]))));
    } else {
      if (!g[ch[rc][0]] && d[ch[rc][0]] <= dx) add(ans, F2(lc, ch[rc][1]));
      if (!g[ch[rc][1]] && d[ch[rc][1]] <= dx) add(ans, F2(lc, ch[rc][0]));
    }
  }
  return f[x] = ans;
}
int F2(int x, int y) {
  if (!x || !y) return F(x | y);
  if (siz[x] + siz[y] & 1) return 0;
  if (G[x].size() == 2 && G[y].size() == 2) return F2(ch[x][0], ch[y][0]);
  if (G[x].size() == 1 && G[y].size() == 1) return 1;
  if (G[x].size() == 2 && G[y].size() == 1) return F(ch[x][0]);
  if (G[x].size() == 1 && G[y].size() == 2) return F(ch[y][0]);
  return 0;
}
int calc(int rt) {
  int ans = 0;
  memset(f, -1, sizeof f);
  for (int i = 0; i < 3; ++i) {
    int L = i ? 0 : 1, R = i == 2 ? 1 : 2;
    int k = ch[rt][i];
    ans = (1ll * F2(ch[rt][L], ch[k][0]) * F2(ch[rt][R], ch[k][1]) + ans) % YL;
    if (G[k].size() > 1)
      ans =
          (1ll * F2(ch[rt][L], ch[k][1]) * F2(ch[rt][R], ch[k][0]) + ans) % YL;
  }
  return 4ll * ans % YL;
}
void dfs(int u, int pa = 0) {
  int cnt = -1;
  siz[u] = 1;
  for (int v : G[u])
    if (v != pa) {
      ch[u][++cnt] = v, dfs(v, u);
      siz[u] += siz[v], g[u] = g[v], d[u] = d[v] + 1;
    }
  if (G[u].size() == 3) g[u] = u, d[u] = 0;
}
int main() {
  int n = in(), rt = 0;
  if (n == 1) return puts("2"), 0;
  for (int i = 2, u, v; i <= n << 1; ++i)
    u = in(), v = in(), G[u].push_back(v), G[v].push_back(u);
  for (int i = 1; i <= n << 1; ++i)
    if (G[i].size() > 3)
      return puts("0"), 0;
    else if (G[i].size() == 3)
      rt = i;
  if (!rt) return printf("%lld\n", (2ll * n * n - n * 2 + 4) % YL), 0;
  dfs(rt);
  printf("%d\n", calc(rt));
  return 0;
}
