#include <bits/stdc++.h>
using namespace std;
vector<int> tr[200001];
int n, C, mxp[200001];
long long an = 0;
int fc(int v = 1, int p = 0) {
  int an = 1;
  bool ok = true;
  for (int i = 0; i < (int)tr[v].size(); ++i)
    if (tr[v][i] != p) {
      int t = fc(tr[v][i], v);
      an += t;
      if (t > n >> 1) ok = false;
    }
  if (n - an > n >> 1) ok = false;
  if (ok) C = v;
  return an;
}
int go(int v = C, int p = 0) {
  int &mx = mxp[v];
  mx = 1;
  for (int i = 0; i < (int)tr[v].size(); ++i)
    if (tr[v][i] != p) mx = max(mx, 1 + go(tr[v][i], v));
  an += mx + 1;
  return mx;
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < (int)n; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    tr[a].push_back(b);
    tr[b].push_back(a);
  }
  fc();
  go();
  --an;
  vector<int> &v = tr[C];
  int mn = 1e9;
  for (int i = 0; i < (int)v.size(); ++i) mn = min(mn, mxp[v[i]]);
  int z = 0;
  for (int i = 0; i < (int)v.size(); ++i)
    if (mxp[v[i]] > mn) ++z;
  if (z == 1) --an;
  printf("%lld\n", an);
}
