#include using namespace std; int MAX_N = 200000; struct unionfind{ vector p; unionfind(int N){ p = vector(N, -1); } int root(int x){ if (p[x] == -1){ return x; } else { p[x] = root(p[x]); return p[x]; } } bool same(int x, int y){ return root(x) == root(y); } void unite(int x, int y){ x = root(x); y = root(y); if (x != y){ p[x] = y; } } }; void dfs(vector> &dp, vector> &c, int v){ for (int w : c[v]){ dfs(dp, c, w); dp[v].first += dp[w].first + 1; dp[v].second += (dp[w].first + 1) * (dp[w].first + 1); } return; } int main(){ int N; cin >> N; assert(1 <= N); assert(N <= MAX_N); vector> E(N); unionfind UF(N); for (int i = 0; i < N - 1; i++){ int u, v; cin >> u >> v; assert(1 <= u); assert(u <= N); assert(1 <= v); assert(v <= N); u--; v--; assert(!UF.same(u, v)); E[u].push_back(v); E[v].push_back(u); } vector p(N, -1); vector> c(N); queue Q; Q.push(0); while (!Q.empty()){ int v = Q.front(); Q.pop(); for (int w : E[v]){ if (w != p[v]){ c[v].push_back(w); p[w] = v; Q.push(w); } } } vector> dp(N); dfs(dp, c, 0); vector ans(N); for (int i = 0; i < N; i++){ ans[i] = (dp[i].first + 1) * (dp[i].first + 1) - dp[i].second; } for (int i = 0; i < N; i++){ cout << ans[i] << endl; } }