#include using namespace std; #define ALL(x) x.begin(),x.end() #define rep(i,n) for(int i=0;i<(n);i++) #define debug(v) cout<<#v<<":";for(auto x:v){cout<bool chmax(T &a,const T &b){if(abool chmin(T &a,const T &b){if(b>n; vector> g(n); rep(i,n-1){ int u,v;cin>>u>>v;u--,v--; g[u].push_back(v); g[v].push_back(u); } vector sz(n,0); vector par(n,-1); function dfs=[&](int pre,int now){ ll res=1; par[now]=pre; for(auto to:g[now])if(to!=pre){ dfs(now,to); res+=sz[to]; } sz[now]=res; }; dfs(-1,0); rep(i,n){ ll res=0; for(auto to:g[i])if(to!=par[i]){ res+=(sz[i]-sz[to])*sz[to]; } res+=sz[i]; cout<