#include <bits/stdc++.h>
using namespace std;
vector<int> adj[300005];
long long dp[300005], s[300005], ans = 0;
long long dfs(int r, int p) {
  s[r] = 1;
  for (auto i : adj[r]) {
    if (i == p) continue;
    s[r] += dfs(i, r);
  }
  return s[r];
}
long long dfs1(int r, int p) {
  dp[r] = s[r];
  for (auto i : adj[r]) {
    if (i == p) continue;
    dp[r] += dfs1(i, r);
  }
  return dp[r];
}
void dfs2(int r, int p) {
  ans = max(ans, dp[r]);
  for (auto i : adj[r]) {
    if (i == p) continue;
    dp[r] -= (dp[i] + s[i]);
    s[r] -= s[i];
    s[i] += s[r];
    dp[i] += (dp[r] + s[r]);
    dfs2(i, r);
    dp[i] -= (dp[r] + s[r]);
    s[i] -= s[r];
    s[r] += s[i];
    dp[r] += (dp[i] + s[i]);
  }
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  int t = 1;
  while (t--) {
    int n;
    cin >> n;
    for (int i = 1; i < n; i++) {
      int a, b;
      cin >> a >> b;
      adj[a].push_back(b);
      adj[b].push_back(a);
    }
    dfs(1, 0);
    dfs1(1, 0);
    dfs2(1, 0);
    cout << ans << endl;
  }
  return 0;
}
