#include <bits/stdc++.h>
using namespace std;
const long long INF = 0x3f3f3f3f;
const int N = 2e5 + 20;
const long long mod = 998244353;
const bool debug = false;
template <class T>
inline void add(T &x, long long y, long long mod) {
  x += y;
  if (x >= mod) x -= mod;
}
template <class T>
inline void add(T &x, long long y, long long z, long long mod) {
  x = y + z;
  if (x >= mod) x -= mod;
}
inline long long qpow(long long x, long long y, long long mod) {
  long long ret = 1;
  while (y) {
    if (y & 1) ret = ret * x % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ret;
}
inline long long qmul(long long x, long long y, long long mod) {
  return ((x * y - (long long)((long double)x * y / mod) * mod) + mod) % mod;
}
inline long long gcd(long long x, long long y) { return x ? gcd(y % x, x) : y; }
inline long long lcm(long long x, long long y) { return x / gcd(x, y) * y; }
vector<int> vc[N];
stack<int> st;
int line[N], en;
bool vis[N];
bool dfs(int u, int o) {
  st.push(u);
  vis[u] = true;
  for (auto it : vc[u]) {
    if (it == o) continue;
    if (vis[it]) {
      while (true) {
        int now = st.top();
        st.pop();
        line[++en] = now;
        if (now == it) break;
      }
      return true;
    }
    if (dfs(it, u)) return true;
  }
  st.pop();
  return false;
}
int dp[2][N], si[N], n;
void dfs1(int u, int o) {
  si[u] = 1;
  for (auto it : vc[u])
    if (!vis[it] && it != o) {
      dfs1(it, u);
      si[u] += si[it];
      dp[0][u] += dp[0][it];
      dp[1][u] = max(dp[1][u], dp[1][it] - dp[0][it] - si[it]);
    }
  dp[1][u] += n + dp[0][u];
  dp[0][u] += si[u];
}
int mx[N], nmx[N];
int main() {
  scanf("%d", &n);
  for (int i = 1, u, v; i <= n; ++i) {
    scanf("%d%d", &u, &v);
    ++u, ++v;
    vc[u].push_back(v);
    vc[v].push_back(u);
  }
  dfs(1, 0);
  memset(vis, false, sizeof vis);
  for (int i = 1; i <= en; ++i) vis[line[i]] = true;
  int sum = 0;
  for (int i = 1; i <= en; ++i) dfs1(line[i], 0);
  for (int i = 1; i <= en; ++i) sum += dp[0][line[i]];
  for (int i = en - 1; i >= 1; --i) {
    int res = 0, pre, nt;
    for (int j = 1; j <= i; ++j) res += si[line[j]];
    for (int j = 1; j <= en; ++j) {
      pre = j - 1;
      if (pre == 0) pre = en;
      nmx[j] = max(mx[pre], mx[j]) + n - res;
      nt = j + i;
      if (nt > en) nt -= en;
      res = res - si[line[j]] + si[line[nt]];
    }
    for (int j = 1; j <= en; ++j) mx[j] = nmx[j];
  }
  int tmp, ans = 0;
  for (int i = 1, id; i <= en; ++i) {
    id = line[i];
    tmp = sum - dp[0][id] - n + si[id] + dp[1][id] + mx[i];
    ans = max(tmp, ans);
  }
  printf("%d\n", ans);
  return 0;
}
