#include using namespace std; using ll = long long; constexpr char newl = '\n'; ll dfs(int cur, int par, const vector< vector >& g, vector& ans) { ll sum = 1; for (int nex : g[cur]) { if (nex == par) continue; ll cnt = dfs(nex, cur, g, ans); sum += cnt; ans[cur] -= cnt * cnt; } ans[cur] += sum * sum; return sum; } int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n; cin >> n; vector< vector > g(n); for (int i = 1; i < n; i++) { int v, w; cin >> v >> w; --v; --w; g[v].push_back(w); g[w].push_back(v); } vector ans(n, 0); dfs(0, -1, g, ans); for (int i = 0; i < n; i++) { cout << ans[i] << newl; } return 0; }