#include <bits/stdc++.h>
using namespace std;
int n;
int ans, sums;
int mx[30010];
int vis[30010], flag[30010];
vector<int> o;
int fath[30010];
int siz[30010], num[30010];
int addnum, vel[30010], ne[30010], head[30010];
int sum[30010];
int sizd;
int dp[2][30010];
void add(int u, int v) {
  addnum++, vel[addnum] = v, ne[addnum] = head[u], head[u] = addnum;
}
void dfs(int u, int fa) {
  vis[u] = 1;
  fath[u] = fa;
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    if (vis[v]) {
      if (o.size()) continue;
      int t = u;
      while (t != v) flag[t] = 1, o.push_back(t), t = fath[t];
      flag[v] = 1;
      o.push_back(v);
    } else
      dfs(v, u);
  }
}
void calc(int u, int fa) {
  siz[u] = 1;
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    if (flag[v]) continue;
    calc(v, u);
    siz[u] += siz[v];
    num[u] += num[v];
  }
  num[u] += siz[u];
}
void solve(int u, int fa, int nums) {
  ans = max(ans, nums + n + num[u] - siz[u]);
  for (int e = head[u]; e; e = ne[e]) {
    int v = vel[e];
    if (v == fa) continue;
    if (flag[v]) continue;
    solve(v, u, nums + num[u] - siz[u] - num[v] + n - siz[v]);
  }
}
int calcs(int x, int y) {
  if (!x) return sum[y];
  return sum[y] - sum[x - 1];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(0, -1);
  for (int u : o) calc(u, -1);
  sizd = o.size();
  for (int i = 0; i < sizd; i++)
    sum[i] = sum[i + sizd] = siz[o[i]], sums += num[o[i]] - siz[o[i]];
  for (int i = 1; i < sizd + sizd; i++) sum[i] = sum[i] + sum[i - 1];
  int now = 0;
  for (int i = sizd; i > 1; i--) {
    now = 1 - now;
    for (int j = 0; j < sizd + sizd; j++) dp[now][j] = 0;
    for (int j = 0; j < sizd + sizd - i + 1; j++) {
      dp[now][j + 1] =
          max(dp[now][j + 1], dp[1 - now][j] + n - calcs(j + 1, j + i - 1));
      dp[now][j] = max(dp[now][j], dp[1 - now][j] + n - calcs(j, j + i - 2));
    }
  }
  for (int i = 0; i < sizd; i++)
    mx[i] = max(dp[now][i], dp[now][i + sizd]) + sums - (num[o[i]] - siz[o[i]]);
  for (int i = 0; i < sizd; i++) solve(o[i], -1, mx[i]);
  printf("%d\n", ans);
}
