#define _USE_MATH_DEFINES #include using namespace std; vector> g; vector ans; int dfs (int cur, int par) { vector v; for (int child : g[cur]) if (child != par) { v.push_back(dfs(child, cur)); } int tot = accumulate(v.begin(), v.end(), 0); for (auto& i : v) ans[cur] += 1LL * i * (tot - i); ans[cur] += 2LL * tot; ans[cur]++; return tot + 1; } signed main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin >> n; g = vector>(n); ans = vector(n); for (int i = 0; i < n - 1; i++) { int u, v; cin >> u >> v; u--; v--; g[u].push_back(v); g[v].push_back(u); } dfs(0, -1); for (auto& i : ans) cout << i << '\n'; return 0; }