#include using namespace std; #define rep(i,n) for(int i = 0; i < (n);i++) #define sz(x) int(x.size()) typedef long long ll; typedef long double ld; typedef pair P; typedef pair PL; constexpr ll INF = (1LL << 60); int main() { int n; cin >> n; vector> g(n); rep(i, n - 1) { int u, v; cin >> u >> v; u--; v--; g[u].emplace_back(v); g[v].emplace_back(u); } vector dp(n, 0); vector sum(n, 0); auto dfs = [&](auto& f, int u = 0, int p = -1)->void{ sum[u] = 1; for (auto v : g[u]) { if (v == p) continue; f(f, v, u); sum[u] += sum[v]; dp[u] -= sum[v] * (sum[v] - 1) / 2; } dp[u] += sum[u] * (sum[u] - 1) / 2; dp[u] *= 2; dp[u]++; }; dfs(dfs); for (int i = 0; i < n; i++) { cout << dp[i] << endl; } return 0; }