#include <bits/stdc++.h>
using namespace std;
vector<vector<long long int>> graph;
vector<long long int> dp;
vector<long long int> numofchild;
long long int ans = 0;
void dfs(long long int src, long long int par = -1) {
  dp[src] = 0;
  numofchild[src] = 1;
  for (long long int child : graph[src]) {
    if (child == par) continue;
    dfs(child, src);
    dp[src] += dp[child];
    numofchild[src] += numofchild[child];
  }
  dp[src] += numofchild[src];
}
void tree_rerooting(long long int src, long long int par = -1) {
  ans = max(ans, dp[src]);
  for (long long int child : graph[src]) {
    if (child == par) continue;
    dp[src] -= dp[child];
    numofchild[src] -= numofchild[child];
    dp[src] -= numofchild[child];
    dp[child] += dp[src];
    numofchild[child] += numofchild[src];
    dp[child] += numofchild[src];
    tree_rerooting(child, src);
    dp[child] -= dp[src];
    numofchild[child] -= numofchild[src];
    dp[child] -= numofchild[src];
    dp[src] += dp[child];
    numofchild[src] += numofchild[child];
    dp[src] += numofchild[child];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  long long int test, u, v;
  scanf("%lld", &test);
  graph.resize(test + 1);
  dp.resize(test + 1);
  numofchild.resize(test + 1);
  for (long long int i = 0; i < test - 1; i++) {
    scanf("%lld %lld", &u, &v);
    u--;
    v--;
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  dfs(0);
  tree_rerooting(0);
  cout << ans << endl;
  return 0;
}
