#include using namespace std; #define REP(i, s) for (int i = 0; i < s; ++i) #define ALL(v) (v).begin(), (v).end() #define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl #define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i) #define DEBUG #define int long long #define INF 1e18 template inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; } template inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; } template ostream& operator << (ostream &s, pair P) { return s << '<' << P.first << ", " << P.second << '>'; } template ostream& operator << (ostream &s, vector P) { for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; } template ostream& operator << (ostream &s, vector > P) { for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; } template ostream& operator << (ostream &s, set P) { EACH(it, P) { s << "<" << *it << "> "; } return s << endl; } template ostream& operator << (ostream &s, map P) { EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; } templatevoid show(vectorv){for (int i = 0; i < v.size(); i++){cerr<>; Graph G; vector depth; vector subtree_size; vectorans; void dfs(const Graph &G, int v, int p, int d) { depth[v] = d; for (auto nv : G[v]) { if (nv == p) continue; // nv が親 p だったらダメ dfs(G, nv, v, d + 1); } // 帰りがけ時に、部分木サイズを求める subtree_size[v] = 1; // 自分自身 for (auto c : G[v]) { if (c == p) continue; subtree_size[v] += subtree_size[c]; // 子のサイズを加える } int cnt=1; int sum=0; int r=0; vectora; for(auto & u : G[v]){ if(u == p){ continue; } //cnt*=subtree_size[u]; r+=subtree_size[u]; a.push_back(subtree_size[u]); sum++; } if(sum==0){ ans[v]=1; } else if(sum==1){ ans[v]=r*2+1; } else { int cnt=0; for (int i = 0; i < a.size(); i++) { for (int j = 0; j < a.size(); j++) { if(i==j){ continue; } cnt+=a[i]*a[j]; } } ans[v]=cnt+1+2*r; } } signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin>>n; G.assign(n,vector()); depth.resize(n,0); subtree_size.resize(n,0); ans.resize(n); for (int i = 0; i < n-1; i++) { int u,v; cin>>u>>v; u--,v--; G[u].push_back(v); G[v].push_back(u); } dfs(G,0,-1,0); for (int i = 0; i < n; i++) { cout<