#include #include std::vectorg[200005]; int vis[200005]; long long son[200005], sum[200005]; long long answer[200005]; void dfs(int u){ vis[u] = son[u] = 1; sum[u] = 0; long long minus = 0; for(int i = 0; i < (int)g[u].size(); i++){ int v = g[u][i]; if(!vis[v]){ dfs(v); minus += sum[v]; son[u] += son[v]; } } answer[u] = son[u]*son[u]-minus; sum[u] = answer[u]+minus; } int main(){ int n; scanf("%d",&n); for(int i = 0; i < n-1; i++){ int u,v; scanf("%d%d",&u,&v); g[u].push_back(v); g[v].push_back(u); } dfs(1); for(int i = 1; i <= n; i++) printf("%lld\n",answer[i]); return 0; }