#include <iostream> #include <vector> using namespace std; using ll = long long ; const int N=2e5+10; ll f[N],g[N],size1[N]; vector<int>gg[N]; void dfs1(int x,int fa){ size1[x]=1; for(auto &t:gg[x]){ if(t==fa)continue; dfs1(t,x); f[x]+=f[t]; size1[x]+=size1[t]; } f[x]+=size1[x]; } ll ans,n; void dfs2(int x,int fa){ if(x!=1){ g[x]=g[fa]+n-2*size1[x]; ans=max(ans,g[x]); } for(auto &t:gg[x]){ if(fa==t)continue; dfs2(t,x); } } int main() { ios::sync_with_stdio(false); cin >> n; for(int i=1,u,v;i<n;i++){ cin>>u>>v; gg[u].push_back(v); gg[v].push_back(u); } dfs1(1,-1); ans=g[1]=f[1]; dfs2(1,-1); cout<<ans; return 0; }