#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 10;
long long n;
long long head[N], a[N];
struct node {
  long long v, nex;
} bian[N << 1];
long long cnt;
void add(long long x, long long y) {
  bian[++cnt].v = y;
  bian[cnt].nex = head[x];
  head[x] = cnt;
}
long long siz[N], d[N], f[N], g[N], zong;
void dfs(long long x, long long fa) {
  siz[x] = 1;
  for (long long i = head[x]; i; i = bian[i].nex) {
    long long v = bian[i].v;
    if (v == fa) continue;
    dfs(v, x);
    siz[x] += siz[v];
    f[x] += f[v];
  }
  f[x] += siz[x];
}
long long ans = 0;
void dp(long long x, long long fa) {
  ans = max(ans, f[x] + g[x] + n - siz[x]);
  long long tmp = 0;
  for (long long i = head[x]; i; i = bian[i].nex)
    if (bian[i].v != fa) tmp += f[bian[i].v];
  for (long long i = head[x]; i; i = bian[i].nex) {
    long long v = bian[i].v;
    if (v == fa) continue;
    g[v] += g[x] + tmp - f[v];
    g[v] += n - siz[v];
    dp(v, x);
  }
}
signed main() {
  cin >> n;
  for (long long i = 1; i < n; i++) {
    long long x, y;
    scanf("%lld%lld", &x, &y);
    add(x, y), add(y, x);
  }
  dfs(1, 0);
  dp(1, 0);
  cout << ans << endl;
}
