#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e4 + 7, mod = 998244353, inf = 1e9, MAXN = 1e6 + 7;
const double eps = 1e-9;
mt19937 rnd(time(0));
int n;
vector<int> gr[maxn];
int p[maxn], dist[maxn];
int used[maxn];
int cycle[maxn];
vector<int> path;
void dfs(int u, int pr, int d) {
  used[u] = 1;
  dist[u] = d;
  p[u] = pr;
  for (auto v : gr[u]) {
    if (v == pr) continue;
    if (!used[v]) {
      dfs(v, u, d + 1);
    } else if (dist[v] < dist[u]) {
      int pp = u;
      while (pp != v) {
        path.push_back(pp);
        cycle[pp] = 1;
        pp = p[pp];
      }
      path.push_back(v);
      cycle[v] = 1;
    }
  }
}
int upper[maxn];
int down[maxn];
int sizz[maxn];
int func[maxn];
int dfs1(int u, int pr, int d) {
  p[u] = pr;
  sizz[u] = 1;
  dist[u] = d;
  for (auto v : gr[u]) {
    if (cycle[v] || v == pr) continue;
    sizz[u] += dfs1(v, u, d + 1);
  }
  return sizz[u];
}
int dow(int u, int pr) {
  down[u] = sizz[u];
  for (auto v : gr[u]) {
    if (cycle[v] || v == pr) continue;
    down[u] += dow(v, u);
  }
  return down[u];
}
int start;
void upp(int u, int pr) {
  if (pr == u) {
    upper[u] = 1;
  } else {
    upper[u] = upper[pr] + sizz[start] - sizz[u] + 1 + down[pr] - down[u] -
               sizz[u] - 1;
  }
  for (auto v : gr[u]) {
    if (cycle[v] || v == pr) continue;
    upp(v, u);
  }
}
int get(int u, int pr) {
  func[u] = upper[u] + down[u] - 1 + (dist[u] + 1) * (n - sizz[start]);
  for (auto v : gr[u]) {
    if (cycle[v] || v == pr) continue;
    func[u] = max(func[u], get(v, u));
  }
  return func[u];
}
vector<int> dp[2];
int pref[2 * maxn];
void solve() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int a, b;
    cin >> a >> b;
    gr[a].push_back(b);
    gr[b].push_back(a);
  }
  dfs(0, 0, 0);
  for (int i = 0; i < n; ++i) {
    if (!cycle[i]) continue;
    dfs1(i, i, 0);
    start = i;
    dow(i, i);
    upp(i, i);
    get(i, i);
  }
  vector<int> have;
  for (auto v : path) have.push_back(v);
  for (auto v : path) have.push_back(v);
  for (int i = 0; i < have.size(); ++i) {
    pref[i + 1] = pref[i] + sizz[have[i]];
  }
  dp[0].resize(have.size());
  dp[1].resize(have.size());
  for (int i = 0; i < have.size(); ++i) {
    int v = have[i];
    dp[0][i] = func[v];
  }
  for (int len = 2; len <= have.size() / 2; ++len) {
    for (int l = 0; l + len - 1 < have.size(); ++l) {
      int r = l + len - 1;
      long long L = dp[0][l + 1] + n - pref[r + 1] + pref[l] + down[have[l]];
      long long R = dp[0][l] + n - pref[r + 1] + pref[l] + down[have[r]];
      dp[1][l] = max(L, R);
    }
    swap(dp[0], dp[1]);
  }
  int ans = 0;
  for (int i = 0; i < 2; ++i) {
    for (int j = 0; j < have.size(); ++j) {
      ans = max(ans, dp[i][j]);
    }
  }
  cout << ans;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(20);
  cout << fixed;
  int t = 1;
  for (int i = 0; i < t; ++i) {
    solve();
  }
  return 0;
}
