#include <bits/stdc++.h>
const int32_t MAX_N = 15000;
struct Vertex {
  bool vis, loop;
  int32_t dp, sz;
  std::vector<int32_t> v;
};
int32_t n, ans, prefSums[MAX_N + 5], dp[MAX_N + 5][2];
Vertex g[MAX_N + 5];
std::vector<int32_t> loop;
void find_loop(int32_t x, int32_t par, std::vector<int32_t> &path) {
  g[x].vis = true;
  path.push_back(x);
  for (auto &y : g[x].v) {
    if (g[y].vis) {
      if (y != par && !g[y].loop) {
        for (int32_t i = path.size() - 1; i >= 0; i--) {
          g[path[i]].loop = true;
          if (path[i] == y) {
            break;
          }
        }
      }
    } else {
      find_loop(y, x, path);
    }
  }
  path.pop_back();
}
void compute_tree_dp(int32_t x, int32_t par) {
  g[x].sz = 1;
  g[x].dp = n;
  for (auto &y : g[x].v) {
    if (y == par || g[y].loop) {
      continue;
    }
    compute_tree_dp(y, x);
    g[x].sz += g[y].sz;
    g[x].dp = std::max(g[x].dp, g[y].dp + n - g[y].sz);
  }
  if (!g[x].loop) {
    g[x].dp -= g[x].sz;
    ans += g[x].sz;
  }
}
void compute_prefix_sums() {
  for (int32_t i = 0; i < loop.size(); i++) {
    prefSums[i] = g[loop[i]].sz;
    if (i != 0) {
      prefSums[i] += prefSums[i - 1];
    }
  }
}
int32_t get_sum(int32_t low, int32_t high) {
  if (low <= high) {
    return prefSums[high] - (low == 0 ? 0 : prefSums[low - 1]);
  } else {
    return get_sum(low, loop.size() - 1) + get_sum(0, high);
  }
}
void compute_loop_dp() {
  compute_prefix_sums();
  for (int32_t len = loop.size(); len >= 1; len--) {
    int32_t p = len % 2;
    for (int32_t low = 0; low < loop.size(); low++) {
      int32_t high = (low + len - 1) % loop.size();
      int32_t nxtLow = low - 1;
      if (nxtLow == -1) {
        nxtLow = loop.size() - 1;
      }
      int32_t nxtHigh = high + 1;
      if (nxtHigh == loop.size()) {
        nxtHigh = 0;
      }
      if (nxtLow == high) {
        continue;
      }
      dp[low][p] = std::max(dp[nxtLow][(p ^ 1)], dp[low][(p ^ 1)]) +
                   get_sum(nxtHigh, nxtLow);
    }
  }
}
int main() {
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cin >> n;
  for (int32_t i = 0; i < n; i++) {
    int32_t u, v;
    std::cin >> u >> v;
    g[u].v.push_back(v);
    g[v].v.push_back(u);
  }
  std::vector<int32_t> path;
  find_loop(0, -1, path);
  for (int32_t i = 0; i < n; i++) {
    if (g[i].loop) {
      loop.push_back(i);
    }
  }
  for (int32_t i = 0; i < loop.size(); i++) {
    compute_tree_dp(loop[i], -1);
  }
  compute_loop_dp();
  int32_t finalAns = 0;
  for (int32_t i = 0; i < loop.size(); i++) {
    finalAns = std::max(finalAns, ans + g[loop[i]].dp + dp[i][1]);
  }
  std::cout << finalAns << '\n';
}
