//g++ 5.cpp -std=c++14 -I . #include using namespace std; using ll = long long; using ld = long double; #define fi first #define se second #define pb push_back int x[100500]; int dist[100500]; int seen[100500]={}; void dfs(vector> g,int now){ seen[now]=1; int z=0; for(int next:g[now]){ if(seen[next]==0){ dist[next]=dist[now]+1; dfs(g,next); z+=x[next]; } } x[now]=z+1; } int main(){ int n; cin>>n; vector> g(n); int v[n-1][2]; for(int i=0;i>a>>b; a--; b--; g[a].pb(b); g[b].pb(a); v[i][0]=a,v[i][1]=b; } dist[0]=0; dfs(g,0); ll ans=0; for(int i=0;idist[b]){ swap(a,b); } ans+=((ll)x[b])*(n-x[b]); } ans*=2; ans+=(ll)n*n; cout<