#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> ADJ;
vector<long long> S;
int N;
int dfs1(int n, int p) {
  int cnt = 1;
  for (int neigh : ADJ[n]) {
    if (neigh != p) cnt += dfs1(neigh, n);
  }
  S[n] = cnt;
  return cnt;
}
long long dfs2(int n, int p) {
  long long res = S[n];
  for (int neigh : ADJ[n]) {
    if (neigh != p) res += dfs2(neigh, n);
  }
  return res;
}
long long dfs3(int n, int p, long long currRes) {
  long long maks = currRes;
  for (int neigh : ADJ[n]) {
    if (neigh != p)
      maks = max({maks, dfs3(neigh, n, currRes + N - 2 * S[neigh])});
  }
  return maks;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> N;
  ADJ = vector<vector<int>>(N);
  S = vector<long long>(N);
  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);
  }
  dfs1(0, -1);
  cout << dfs3(0, -1, dfs2(0, -1));
}
