#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 checker(long long v, long long s, long long val) {
  ans = max(ans, val);
  for (auto i : vect[v]) {
    if (i == s) {
      continue;
    }
    checker(i, v, val - sub[i] + n - sub[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);
  ans = dp[1];
  checker(1, 0, ans);
  cout << ans << '\n';
  return 0;
}
