#include #include #include using namespace atcoder; using mint = modint998244353; using namespace std; #define rep(i,n) for(int i=0;i<(n);i++) #define Inf 1000000001 int n; vector> E; vector ans; int get(int cur,int p){ int ret = 0; rep(i,E[cur].size()){ int to = E[cur][i]; if(to==p)continue; ret += get(to,cur); if(cur > to)ret++; } return ret; } int dfs(int cur,int p,int cv){ ans[cur] = cv; rep(i,E[cur].size()){ int to = E[cur][i]; if(to==p)continue; if(cur > to){ dfs(to,cur,cv - 1); } else{ dfs(to,cur,cv+1); } } return 0; } int main(){ cin>>n; E.resize(n); ans.resize(n,0); rep(i,n-1){ int u,v; cin>>u>>v; u--;v--; E[u].push_back(v); E[v].push_back(u); } int t = get(0,-1); dfs(0,-1,t); rep(i,n){ cout<