#include using namespace std; //#define int long long #define REP(i,m,n) for(int i=(m);i<(n);i++) #define rep(i,n) REP(i,0,n) #define pb push_back #define all(a) a.begin(),a.end() #define rall(c) (c).rbegin(),(c).rend() #define mp make_pair #define endl '\n' //#define vec vector //#define mat vector > #define fi first #define se second #define double long double typedef long long ll; typedef unsigned long long ull; typedef pair pll; //typedef long double ld; typedef complex Complex; const ll INF=1e9+7; const ll MOD=998244353; const ll inf=INF*INF; const ll mod=2; const ll MAX=100010; const double PI=acos(-1.0); typedef vector > mat; typedef vector vec; ll n; vector > G(MAX); ll cnt=0; void dfs(ll i,ll p){ for(auto e:G[i]){ if(e==p)continue; if(eans(MAX); void dfs2(ll i,ll p){ for(auto e:G[i]){ if(e==p)continue; if(e>i)cnt++; else cnt--; dfs2(e,i); if(e>i)cnt--; else cnt++; } ans[i]=cnt; } void solve(){ ll n;cin>>n; rep(i,n-1){ ll a,b;cin>>a>>b; a--;b--; G[a].pb(b); G[b].pb(a); } ll st=-1; rep(i,n)if(G[i].size()==1)st=i; dfs(st,-1); dfs2(st,-1); rep(i,n){ cout<