#include using namespace std; #define rep(i, n) for(int i = 0; i < n; i++) #define rep2(i, x, n) for(int i = x; i <= n; i++) #define rep3(i, x, n) for(int i = x; i >= n; i--) #define elif else if #define sp(x) fixed << setprecision(x) #define pb push_back #define eb emplace_back #define all(x) x.begin(), x.end() #define sz(x) (int)x.size() using ll = long long; using ld = long double; using pii = pair; using pil = pair; using pli = pair; using pll = pair; const ll MOD = 1e9+7; //const ll MOD = 998244353; const int inf = (1<<30)-1; const ll INF = (1LL<<60)-1; const ld EPS = 1e-10; template bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;}; template bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;}; const int MAX_V = 2e5; vector es[MAX_V]; ll ans[MAX_V]; ll dfs(int now, int pre){ ll ret = 0; ans[now] = 0; vector v; for(auto &e: es[now]){ if(e == pre) continue; ll s = dfs(e, now); v.pb(s); ret += s, ans[now] -= s*s; } ans[now] += ret*ret; ans[now] += 2*ret+1; return ret+1; } int main(){ int N; cin >> N; rep(i, N-1){ int u, v; cin >> u >> v; u--, v--; es[u].pb(v), es[v].pb(u); } dfs(0, -1); rep(i, N){ cout << ans[i] << endl; } }