#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> adj[200013];
long long solve2cache[200013];
long long subtreeSize[200013];
void getSubtreeSizes(int cur, int par) {
  subtreeSize[cur] = 1;
  for (int next : adj[cur]) {
    if (next == par) continue;
    getSubtreeSizes(next, cur);
    subtreeSize[cur] += subtreeSize[next];
  }
}
long long solve2(int cur, int par) {
  if (solve2cache[cur] != -1) return solve2cache[cur];
  solve2cache[cur] = subtreeSize[cur];
  for (int next : adj[cur]) {
    if (next == par) continue;
    solve2cache[cur] += solve2(next, cur);
  }
  return solve2cache[cur];
}
long long solve(int cur, int par, long long outsideBoost) {
  long long goingDownAnswerSum = 0;
  for (int next : adj[cur]) {
    if (next == par) continue;
    goingDownAnswerSum += solve2(next, cur);
  }
  long long answer = solve2(cur, par) + outsideBoost;
  for (int next : adj[cur]) {
    if (next == par) continue;
    long long tempAnswer =
        solve(next, cur, outsideBoost + subtreeSize[cur] - subtreeSize[next]);
    tempAnswer += goingDownAnswerSum - solve2(next, cur);
    tempAnswer += outsideBoost + subtreeSize[cur] - subtreeSize[next];
    answer = max(answer, tempAnswer);
  }
  return answer;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n; i++) {
    solve2cache[i] = -1;
  }
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  getSubtreeSizes(0, -1);
  cout << solve(0, -1, 0) << endl;
}
