#include #define M_PI 3.14159265358979323846 // pi using namespace std; typedef long long ll; typedef unsigned long long ull; typedef vector VI; typedef pair P; typedef tuple t3; typedef tuple t4; typedef tuple t5; #define rep(a,n) for(ll a = 0;a < n;a++) #define repi(a,b,n) for(ll a = b;a < n;a++) using namespace std; static const ll INF = 1e15; const ll mod = 1000000007; vector> g; vector dp; vector> children; int dfs(int current, int parent) { if (dp[current]) { return dp[current]; } int sum = 1; for (int i = 0; i < g[current].size(); i++) { if (g[current][i] != parent) { auto d = dfs(g[current][i], current); sum += d; children[current].push_back(d); } } dp[current] = sum; return sum; } int main() { int n; cin >> n; g.resize(n); dp.resize(n); children.resize(n); rep(i, n - 1) { int v, w; cin >> v >> w; v--; w--; g[v].push_back(w); g[w].push_back(v); } dfs(0, -1); rep(i, n) { ll total = 0; ll cSum = 0; for (auto child : children[i]){ total += child * cSum * 2; cSum += child; } total += cSum * 2 + 1; cout << total << endl; } return 0; }