#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const long long MNOGO = 2e9;
const long long MD = 998244353;
const double EPS = 1e-7;
struct pryama {
  double a, b, c;
};
class segmentTree {
 public:
  segmentTree* left = nullptr;
  segmentTree* right = nullptr;
  long long tl = 0, tr = 1 << 22;
  long long val = 0;
  void createSons() {
    if (left == nullptr) {
      left = new segmentTree();
      left->tl = tl;
      left->tr = (tl + tr) / 2;
    }
    if (right == nullptr) {
      right = new segmentTree();
      right->tr = tr;
      right->tl = (tl + tr) / 2 + 1;
    }
  }
  pair<long long, long long> merge(pair<long long, long long> l,
                                   pair<long long, long long> r) {
    if (l.first == r.first) {
      return {l.first, r.second};
    }
    if (l.first > r.first) {
      return l;
    } else {
      return r;
    }
  };
  void update(long long pos, long long q) {
    if (tl == tr) {
      val = q;
      return;
    }
    createSons();
    long long md = (tl + tr) / 2;
    if (pos <= md) {
      left->update(pos, q);
    } else {
      right->update(pos, q);
    }
    val = min(left->val, right->val);
  }
  long long get(long long l, long long r) {
    if (l > r) {
      return 0;
    }
    if (l > tr || r < tl) {
      return 0;
    }
    if (tl >= l && tr <= r) {
      return val;
    }
    createSons();
    return min(left->get(l, r), right->get(l, r));
  }
  void build(long long l, long long r, long long* a) {
    if (tl > tr) {
      return;
    }
    if (l > tr || r < tl) {
      return;
    }
    if (tl == tr) {
      val = a[tl];
      return;
    }
    createSons();
    left->build(l, r, a);
    right->build(l, r, a);
    val = min(left->get(l, r), right->get(l, r));
  }
};
long long n;
vector<long long> g[300005];
long long sz[300005];
long long sumsz[300005];
void precalcSz(long long v, long long pred) {
  for (auto i : g[v]) {
    if (i != pred) {
      precalcSz(i, v);
      sz[v] += sz[i];
      sumsz[v] += sumsz[i];
    }
  }
  sz[v]++;
  sumsz[v] += sz[v];
}
long long tmpsolve(long long v, long long pred) {
  long long ans = sz[v];
  for (auto i : g[v]) {
    if (i != pred) {
      ans += tmpsolve(i, v);
    }
  }
  return ans;
}
long long solve(long long num, long long v, long long pred) {
  long long sumsolves = 0;
  for (auto i : g[v]) {
    if (i != pred) {
      sumsolves += sumsz[i];
    }
  }
  long long mx = 0;
  for (auto i : g[v]) {
    if (i != pred) {
      long long fsolve = solve(num, i, v);
      long long cur =
          fsolve + sumsolves - sumsz[i] + (num - sz[v]) + (sz[v] - sz[i]);
      mx = max(cur, mx);
    }
  }
  if (mx == 0) {
    return num;
  }
  return mx;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, m;
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long u, v;
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  precalcSz(1, 0);
  cout << solve(sz[1], 1, 0) << '\n';
}
