#include #include using namespace std; using namespace atcoder; using ll = long long; using db = long double; using ch = char; using bl = bool; using st = string; using pll = pair; using psl = pair; using vst = vector; using vch = vector; using vvch = vector; using vbl = vector; using vvbl = vector; using vdb = vector; using vpll = vector; using vvpll = vector; using vpsl = vector; using vi = vector; using vvi = vector; using vvvi = vector; using vvvvi = vector; using vll = vector; using vvll = vector; using vvvll = vector; using vvvvll = vector; using vvvvvll = vector; template using pq = priority_queue; template using pqg = priority_queue,greater>; #define all(A) A.begin(),A.end() #define sz(A) (ll)A.size() #define pb(a) push_back(a) #define mp(a,b) make_pair(a,b) #define rep(i, n) for (ll i = 0; i < (ll)(n); i++) #define rrep(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);i++) #define drep(i,n) for(ll i=(ll)n-1; i>=0; i--) #define drrep(i,a,b) for(ll i=(ll)a; i>=(ll)b; i--) using mint = modint998244353; // using mint = modint1000000007; using vm = vector; using vvm = vector; using vvvm = vector; const ll mod = 998244353; const ll INF = 3e18; template inline bool chmin(T &a, T b) { if (a>b) { a=b; return true; } return false; } template inline bool chmax(T &a, T b) { if (a0) { if(n%2==1)res*=a; a*=a; n/=2; } return res; } ll Pow(ll a, ll n, ll p) { ll res=1; while(n>0) { a%=p; if(n%2==1)res*=a; a*=a; res%=p; n/=2; } return res; } void yn(bl ok) { cout << (ok?"Yes":"No") << endl; return; } ll N,dist[300010],chi[300010],par[300010],ans[300010]; vll G[300010]; int main() { cin>>N; rep(i,N-1) { ll u,v; cin>>u>>v; u--, v--; G[u].pb(v); G[v].pb(u); } queue q; vbl vis(N,0); rep(i,N)dist[i]=INF; q.push(0); vis[0]=1; dist[0]=0; while(!q.empty()) { ll v=q.front(); q.pop(); for(ll u:G[v]) { if(vis[u])continue; chi[v]++; par[u]=v; q.push(u); dist[u]=dist[v]+1; vis[u]=1; } } rep(i,N) { if(dist[i]>=2)ans[i]=1; if(dist[i]>=1)ans[i]+=(chi[par[i]]-1); for(ll j:G[i])if(j!=par[i])ans[i]+=chi[j]; } rep(i,N)cout << ans[i] << endl; return 0; }