#include <bits/stdc++.h>
using namespace std;
vector<long long> sub_size, sub_res;
vector<vector<long long>> g;
vector<bool> visited;
long long res, n;
void precompute(long long v) {
  sub_size[v] = 1;
  sub_res[v] = 0;
  for (long long u : g[v]) {
    if (!visited[u]) {
      visited[u] = true;
      precompute(u);
      sub_res[v] += sub_res[u];
      sub_size[v] += sub_size[u];
    }
  }
  sub_res[v] += sub_size[v];
}
void reroot(long long v) {
  for (long long u : g[v]) {
    if (!visited[u]) {
      long long old_parent_res = sub_res[v];
      long long old_parent_size = sub_size[v];
      long long old_child_res = sub_res[u];
      long long old_child_size = sub_size[u];
      long long new_parent_size = old_parent_size - old_child_size;
      long long new_parent_res =
          old_parent_res - old_child_size - old_child_res;
      long long new_child_size = old_parent_size;
      long long new_child_res =
          old_child_res - old_child_size + new_child_size + new_parent_res;
      sub_res[v] = new_parent_res;
      sub_size[v] = new_parent_size;
      sub_res[u] = new_child_res;
      sub_size[u] = new_child_size;
      res = max(res, new_child_res);
      visited[u] = true;
      reroot(u);
      sub_res[v] = old_parent_res;
      sub_size[v] = old_parent_size;
      sub_res[u] = old_child_res;
      sub_size[u] = old_child_size;
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  long long u, v;
  cin >> n;
  g.resize(n);
  sub_size.resize(n);
  sub_res.resize(n);
  visited.resize(n, false);
  for (long long i = 1; i < n; i++) {
    cin >> u >> v;
    u--;
    v--;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  visited[0] = true;
  precompute(0);
  res = sub_res[0];
  visited.clear();
  visited.resize(n, false);
  visited[0] = true;
  reroot(0);
  cout << res << "\n";
}
