#include <bits/stdc++.h>
using namespace std;
int nxt[1000005], head[1000005], to[1000005], S[1000005], T[1000005],
    Size[1000005], E[1000005], tot, n;
bool flag[1000005];
long long F[1000005][2], FF[2][1000005], sum, ans;
bool found;
int read() {
  char c = getchar();
  int ans = 0;
  while (c < '0' || c > '9') c = getchar();
  while (c >= '0' && c <= '9')
    ans = (ans << 1) + (ans << 3) + (c ^ 48), c = getchar();
  return ans;
}
void add(int u, int v) {
  nxt[++tot] = head[u];
  head[u] = tot;
  to[tot] = v;
  return;
}
void DFS(int x, int fa) {
  S[T[x] = ++S[0]] = x;
  for (register int i = head[x]; i; i = nxt[i]) {
    if (to[i] == fa) continue;
    if (T[to[i]]) {
      for (register int j = T[to[i]]; j <= S[0]; j++)
        flag[S[j]] = 1, E[++E[0]] = S[j];
      found = 1;
      return;
    }
    DFS(to[i], x);
    if (found) return;
  }
  S[0]--, T[x] = 0;
  return;
}
void dfs(int x, int fa) {
  Size[x] = 1;
  bool Flag = 0;
  for (register int i = head[x]; i; i = nxt[i])
    if (to[i] != fa && !flag[to[i]])
      dfs(to[i], x), Size[x] += Size[to[i]], Flag = 1;
  if (!Flag) {
    F[x][0] = 1;
    F[x][1] = n;
    return;
  }
  for (register int i = head[x]; i; i = nxt[i])
    if (to[i] != fa && !flag[to[i]]) F[x][0] += F[to[i]][0];
  for (register int i = head[x]; i; i = nxt[i])
    if (to[i] != fa && !flag[to[i]])
      F[x][1] =
          max(F[x][1], F[x][0] - F[to[i]][0] + F[to[i]][1] + n - Size[to[i]]);
  F[x][0] += Size[x];
  return;
}
int main() {
  n = read();
  for (register int i = 1, u, v; i <= n; i++)
    u = read() + 1, v = read() + 1, add(u, v), add(v, u);
  DFS(1, 0);
  for (register int i = 1; i <= E[0]; i++) dfs(E[i], 0), sum += F[E[i]][0];
  for (register int i = 1; i <= E[0]; i++) E[i + E[0]] = E[i];
  for (register int l = 2; l < E[0]; l++)
    for (register int i = 1; i + l - 1 <= E[0] + E[0]; i++) {
      int j = i + l - 1;
      FF[l & 1][i] = min(FF[(l - 1) & 1][i] + (l - 1) * Size[E[j]],
                         FF[(l - 1) & 1][i + 1] + (l - 1) * Size[E[i]]);
    }
  for (register int i = 1; i <= E[0]; i++)
    ans =
        max(ans, sum - F[E[i]][0] + F[E[i]][1] + (E[0] - 2) * (n - Size[E[i]]) -
                     FF[(E[0] - 1) & 1][i + 1]);
  printf("%lld", ans);
  return 0;
}
