#include <bits/stdc++.h>
using namespace std;
const int N = (int)15e4 + 123, inf = 1e9, mod = 1e9 + 7, M = 511;
const long long INF = (long long)1e18;
int n, used[N], m, p[N], cnt[N], cnt2[N], sum2[2][N];
long long dp[N], sum[N], dp2[N], ans[2][N], Ans;
bool iscycle[N];
vector<int> g[N], c;
bool findc(int v, int pr = -1) {
  used[v] = 1;
  for (int to : g[v]) {
    if (to == pr) continue;
    if (used[to] == 0) {
      p[v] = to;
      if (findc(to, v)) return 1;
    } else if (used[to] == 1) {
      int x = to;
      while (x != v) {
        c.push_back(x);
        x = p[x];
      }
      c.push_back(v);
      return 1;
    }
  }
  used[v] = 2;
  return 0;
}
void dfs(int v, int pr = -1) {
  cnt[v]++;
  for (int to : g[v]) {
    if (iscycle[to] || to == pr) continue;
    dfs(to, v);
    cnt[v] += cnt[to];
    sum[v] += sum[to];
  }
  if (iscycle[v]) {
    cnt2[v] = cnt[v];
    cnt[v] = n;
  }
  sum[v] += cnt[v];
}
void dfs2(int v, int pr, int cv) {
  dp[v] = sum[v];
  dp2[cv] = max(dp2[cv], dp[v]);
  for (int to : g[v]) {
    if (iscycle[to] || to == pr) continue;
    long long sumv = sum[v];
    long long cntv = cnt[v];
    sum[v] -= cnt[v];
    sum[v] -= sum[to];
    cnt[v] -= cnt[to];
    sum[to] -= cnt[to];
    cnt[to] += cnt[v];
    sum[v] += cnt[v];
    sum[to] += sum[v];
    sum[to] += cnt[to];
    dfs2(to, v, cv);
    sum[v] = sumv;
    cnt[v] = cntv;
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(NULL);
  cin >> n;
  for (int i = 0; i < n; ++i) {
    int x, y;
    cin >> x >> y;
    g[x].push_back(y);
    g[y].push_back(x);
  }
  findc(0);
  m = c.size();
  for (int i = 0; i < m; ++i) iscycle[c[i]] = 1;
  for (int i = 0; i < m; ++i) dfs(c[i]);
  for (int i = 0; i < m; ++i) dfs2(c[i], -1, c[i]);
  for (int i = 0; i < m; ++i) {
    ans[0][i] = dp2[c[i]];
    sum2[0][i] = cnt2[c[i]];
  }
  int x = 0, y = 1;
  for (int len = 1; len < m; ++len) {
    swap(x, y);
    for (int i = 0; i < m - 1; ++i) {
      ans[x][i] = max(ans[y][i + 1] + dp[c[i]] - sum2[y][i + 1],
                      ans[y][i] + dp[c[(i + len) % m]] - sum2[y][i]);
      sum2[x][i] = sum2[y][i + 1] + cnt2[c[i]];
    }
    ans[x][m - 1] =
        max(ans[y][0] + dp[c[m - 1]] - sum2[y][0],
            ans[y][m - 1] + dp[c[(m - 1 + len) % m]] - sum2[y][m - 1]);
    sum2[x][m - 1] = sum2[y][0] + cnt2[c[m - 1]];
  }
  for (int i = 0; i < m; ++i) Ans = max(Ans, ans[x][i]);
  cout << Ans << endl;
  cerr << (clock() + 0.0) / 1000.0 << endl;
  return 0;
}
