#include using namespace std; using ll = long long; int n; vector> hen; vector dp; vector ans; int dfs(int v, int par) { if(dp[v])return dp[v]; ll sum = 1; ll res = 0; for(auto i : hen[v]) { if(i == par)continue; ll cur = dfs(i, v); sum += cur; res -= cur * cur; } res += (sum) * sum; ans[v] =res; return dp[v] = sum; } int main() { cin >> n; hen.resize(n), dp.resize(n), ans.resize(n); for(int i = 0; i < n - 1; i++) { int s, t; cin >> s >> t; s--, t--; hen[s].emplace_back(t); hen[t].emplace_back(s); } dfs(0, -1); for(int i = 0; i < n; i++) { cout << ans[i] << endl; } }