#include using namespace std; 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; vector> E(N); for (int i = 0; i < N - 1; i++){ int u, v; cin >> u >> v; 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); for (int i = 0; i < N; i++){ cout << (dp[i].first + 1) * (dp[i].first + 1) - dp[i].second << endl; } }