#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> grf[200000 + 5];
long long subTree[200000 + 5];
long long dp[200000 + 5];
long long ans;
long long dfs1(int node, int par) {
  long long ret = 0;
  for (int i = 0; i < grf[node].size(); i++) {
    int nxt = grf[node][i];
    if (nxt == par) continue;
    ret += dfs1(nxt, node);
    subTree[node] += subTree[nxt];
  }
  subTree[node]++;
  ret += subTree[node];
  return ret;
}
void dfs2(int node, int par) {
  dp[node] = node == 1 ? dp[1] : (long long)n - 2 * subTree[node] + dp[par];
  ans = max(ans, dp[node]);
  for (int i = 0; i < grf[node].size(); i++) {
    int nxt = grf[node][i];
    if (nxt == par) continue;
    dfs2(nxt, node);
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    grf[u].push_back(v);
    grf[v].push_back(u);
  }
  ans = 0;
  dp[1] = dfs1(1, 1);
  dfs2(1, 1);
  cout << ans << endl;
  return 0;
}
