#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> vect[300000];
long long sub[300000];
long long dp[300000];
long long ans = -1;
void dfs(long long v, long long s) {
  sub[v] = 1;
  for (auto i : vect[v]) {
    if (i != s) {
      dfs(i, v);
      sub[v] += sub[i];
      dp[v] += dp[i];
    }
  }
  dp[v] += sub[v];
}
void reroot(long long v, long long s) {
  ans = max(ans, dp[v]);
  for (auto i : vect[v]) {
    if (i == s) {
      continue;
    }
    dp[v] -= dp[i];
    dp[v] -= sub[i];
    sub[v] -= sub[i];
    sub[i] += sub[v];
    dp[i] += sub[v];
    dp[i] += dp[v];
    reroot(i, v);
    dp[i] -= dp[v];
    dp[i] -= sub[v];
    sub[i] -= sub[v];
    sub[v] += sub[i];
    dp[v] += sub[i];
    dp[v] += dp[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (long long i = 0; i < n - 1; i++) {
    long long x, y;
    cin >> x >> y;
    vect[x].push_back(y);
    vect[y].push_back(x);
  }
  dfs(1, 0);
  reroot(1, 0);
  cout << ans << '\n';
  return 0;
}
