#include #define ll long long #define INF 1000000005 #define MOD 1000000007 #define EPS 1e-10 #define rep(i,n) for(int i=0;i<(int)(n);++i) #define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i) #define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i) #define each(a,b) for(auto& (a): (b)) #define all(v) (v).begin(),(v).end() #define len(v) (int)(v).size() #define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end()) #define cmx(x,y) x=max(x,y) #define cmn(x,y) x=min(x,y) #define fi first #define se second #define pb push_back #define show(x) cout<<#x<<" = "<<(x)<auto&operator<<(ostream&o,pairp){return o<<"{"<auto&operator<<(ostream&o,sets){for(auto&e:s)o< auto&operator<<(ostream&o,priority_queueq){while(!q.empty())o<auto&operator<<(ostream&o,mapm){for(auto&e:m)o<auto&operator<<(ostream&o,vectorv){for(auto&e:v)o<void ashow(T t,A...a){cout< P; typedef pair pll; typedef vector vi; typedef vector vl; typedef vector vvi; typedef vector vvl; typedef vector

vp; typedef vector vd; typedef vector vs; const int MAX_N = 200005; vector G[MAX_N], graph[2*MAX_N]; int val[MAX_N], ver[MAX_N], ans[MAX_N]; int n; class UF { private: int sz; vector par,nrank; public: UF(){} UF(int node_size){ sz = node_size; par.resize(sz),nrank.resize(sz,0); rep(i,sz) par[i] = i; } int find(int x){ if(par[x] == x){ return x; }else{ return par[x] = find(par[x]); } } void unite(int x,int y) { x = find(x),y = find(y); if(x == y) return; if(nrank[x] < nrank[y]) swap(x,y); par[y] = x; if(nrank[x] == nrank[y]) nrank[x]++; } bool same(int x,int y){ return find(x) == find(y); } }; void dfs(int u, int p, int depth) { if(u < n) ans[u] += depth; each(v, graph[u]){ if(v != p){ dfs(v, u, depth + 1); } } } int main() { cin.tie(0); ios::sync_with_stdio(false); cin >> n; rep(i,n-1){ int u,v; cin >> u >> v; if(u > v) swap(u, v); G[v-1].pb(u-1); ver[i+1] = i+1; } UF uf(n); int nx = n; rep(i,n){ if(len(G[i]) == 0) continue; ans[i]--; graph[nx].pb(i); each(v, G[i]) graph[nx].pb(ver[uf.find(v)]); each(v, G[i]) uf.unite(i, v); ver[uf.find(i)] = nx++; } dfs(nx-1, -1, 1); rep(i,n){ cout << ans[i] << "\n"; } return 0; }