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