#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define llint long long #define inf 1e18 #define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++) #define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++) #define chmin(x, y) (x) = min((x), (y)) #define chmax(x, y) (x) = max((x), (y)) using namespace std; typedef pair P; llint n; vector G[200005]; llint a[200005], b[200005]; void dfs(int v, int p) { a[v] = 1; for(int i = 0; i < G[v].size(); i++){ if(G[v][i] == p) continue; dfs(G[v][i], v); a[v] += a[G[v][i]]; } b[v] = a[v] * a[v]; for(int i = 0; i < G[v].size(); i++){ if(G[v][i] == p) continue; b[v] -= a[G[v][i]] * a[G[v][i]]; } } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> n; llint u, v; for(int i = 0; i < n-1; i++){ cin >> u >> v; G[u].push_back(v); G[v].push_back(u); } dfs(1, -1); for(int i = 1; i <= n; i++) cout << b[i] << endl; return 0; }