#include using namespace std; #define int long long #define ii pair #define app push_back #define all(a) a.begin(), a.end() #define bp __builtin_popcountll #define ll long long #define mp make_pair #define f first #define s second #define Time (double)clock()/CLOCKS_PER_SEC const int N = 1e5+7; vector tree[N]; int ans[N]; int cnt[N]; void dfs(int u, int p) { cnt[u] = 1; for (int v : tree[u]) { if (v == p) continue; dfs(v, u); cnt[u] += cnt[v]; } ans[u] = cnt[u] * cnt[u]; for (int v : tree[u]) { if (v == p) continue; ans[u] -= cnt[v] * cnt[v]; } } signed main() { #ifdef HOME freopen("input.txt", "r", stdin); #else #define endl '\n' ios_base::sync_with_stdio(0); cin.tie(0); #endif int n; cin >> n; for (int i = 1; i <= n - 1; ++i) { int u, v; cin >> u >> v; tree[u].app(v); tree[v].app(u); } dfs(1, 1); for (int i = 1; i <= n; ++i) cout << ans[i] << endl; }