#include #include #include #include #include #include #include #include #include using namespace std; typedef long long ll; #define int long long #define double long double typedef vector VI; typedef pair pii; typedef vector VP; typedef vector VS; typedef priority_queue PQ; templatebool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; } templatebool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; } #define fore(i,a) for(auto &i:a) #define REP(i,n) for(int i=0;i, greater > q2; int comb(int a, int b) { if (a < b)return 0; if (b > a - b) return comb(a, a - b); int ansMul = 1; int ansDiv = 1; for (int i = 0; i < b; i++) { ansMul *= (a - i); ansDiv *= (i + 1); } return ansMul / ansDiv; } int N; VI G[200010]; int ans[200010]; int t[200010];//size of subtree int dp[200010]; void dfs1(int now, int pa) { fore(to, G[now]) { if (to == pa)continue; dfs1(to, now); } t[now]++; if (pa != -1)t[pa] += t[now]; return; } void dfs(int now, int pa) { int cnt = comb(t[now], 2) * 2 + t[now]; fore(to, G[now]) { if (to == pa)continue; dfs(to, now); cnt -= dp[to]; dp[now] += dp[to]; } //cout << now << " " << cnt << endl; ans[now] = cnt; dp[now] += cnt; } signed main() { cin.tie(0); ios::sync_with_stdio(false); cin >> N; REP(i, N - 1) { int a, b; cin >> a >> b; a--; b--; G[a].push_back(b); G[b].push_back(a); } dfs1(0, -1); dfs(0, -1); REP(i, N) cout <