#include using namespace std; using ll = long long; vector> graph; vector sz, par; void dfs(int v) { sz[v] = 1; for (auto u : graph[v]) if (par[v] != u) { par[u] = v; dfs(u); sz[v] += sz[u]; } } int main() { cin.tie(0); ios_base::sync_with_stdio(false); int n; cin >> n; graph.resize(n); for (int i = 0; i < n-1; i++) { int u, v; cin >> u >> v; u--; v--; graph[u].push_back(v); graph[v].push_back(u); } sz.assign(n, 0); par.assign(n, -1); dfs(0); vector result(n); for (int v = 0; v < n; v++) result[v] = (ll)sz[v] * sz[v]; for (int v = 0; v < n; v++) for (auto u : graph[v]) if (u != par[v]) result[v] -= result[u]; for (int v = 0; v < n; v++) cout << result[v] << '\n'; }