#include using namespace std; using LL = long long; using ULL = unsigned long long; #define rep(i,n) for(int i=0; i<(n); i++) const int xN = 200000; int N; vector E[xN]; int P[xN]; LL Z[xN]; LL ans[xN]; void dfs(int p) { Z[p] = 1; for (int e : E[p]) { if (P[p] == e) continue; P[e] = p; dfs(e); Z[p] += Z[e]; ans[p] -= Z[e] * Z[e]; } ans[p] += Z[p] * Z[p]; } int main() { int N; scanf("%d", &N); rep(i, N - 1) { int u, v; scanf("%d%d", &u, &v); u--; v--; E[u].push_back(v); E[v].push_back(u); } rep(i, N) P[i] = -1; dfs(0); rep(i, N) printf("%lld\n", ans[i]); return 0; }