stablegradients/pie-gem5-bysrc huggingface dataset:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define fi first

#define se second

#define pb push_back

#define forn(i,n) for(int i=0;i<(n);i++)

#define for1(i,n) for(int i=1;i<=n;i++)

#define forr(i,n) for(int i=n;i>=0;i--)

#define all(x) x.begin(), x.end()

const int MAXN = 2e5 +5;



void fio(){

  ios::sync_with_stdio(0);

  cin.tie(0);

  cout.tie(0);

}



vector <vector <int> > adj(MAXN);

int n;

vector <int> in(MAXN), out(MAXN), vec;



void dfs(int i, int p = -1){

  vec.pb(i);

  in[i] = vec.size()-1;

  for(auto j:adj[i])

    if(j!=p) dfs(j,i);

  out[i] = vec.size()-1;

}







int main(){

  fio();

  int q; cin>>n>>q;

  for(int i=0;i<n-1;i++){

    int u,v; cin>>u>>v;

    adj[u].pb(v);

    adj[v].pb(u);

    } 

  dfs(1);

  vector <LL> an(n+5);

  while(q--){

    LL u,x; cin>>u>>x;

    an[in[u]]+=x;

    an[out[u]+1]-=x;

  }

  for1(i,n)

    an[i]+=an[i-1];

  for1(i,n) 

    cout<<an[in[i]]<<" ";

  cout<<endl;

  return 0;

}




// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



const int maxn = 2e5 + 3;



int n, q, a, b;

vector <int> graph[maxn];

int ar[maxn], ans[maxn];



void dfs(int i, int ansPar, int par){

    ans[i] = ansPar + ar[i];

    for (int u : graph[i])

        if (u != par)

            dfs(u, ans[i], i);

}



int main() {

    cin >> n >> q;

    for (int i = 1; i < n; i++) {

        cin >> a >> b;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }

    for (int i = 0; i < q; i++) {

        cin >> a >> b;

        ar[a] += b;

    }

    dfs(1, 0, 0);

    for(int i = 1; i < n + 1; i++)

        cout << ans[i] << " ";

    cout << endl;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,n) for (int i = 0; i < (n); ++i)



vector<int> to[200005];

ll ans[200005];



void dfs(int v, int p=-1){

    for(int i:to[v]){

        if(i == p) continue; // 親ノードには戻らない

        ans[i] += ans[v];

        dfs(i,v);

    }

}



int main(){

    int N,Q;

    cin >> N >> Q;

    for(int i=0;i<N-1;i++){

        int a,b;

        cin >> a >> b;

        a--; b--;   // ０始まりのために-1

        to[a].push_back(b);

        to[b].push_back(a); // aがbの親とは限らないので双方向に辺を張る

    }

    for(int i=0;i<Q;i++){

        int p;

        ll x;

        cin >> p >> x;

        p--;

        ans[p] += x;

    }



    dfs(0);



    for(int i=0;i<N-1;i++){

        cout << ans[i] << " ";

    }

    cout << ans[N-1] << endl;

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define INF (1LL<<50)

#define MOD 1000000007



typedef vector<vector<int>> Graph; 

vector<bool> seen;

vector<ll> counter,ADD;

void dfs(Graph &T,int num,ll cnt){

    seen[num]=true;

    counter[num] = cnt;

    for(int i=0;i<T[num].size();i++){

        if(seen[T[num][i]])continue;

        dfs(T,T[num][i],cnt+ADD[T[num][i]]);

    }

}



int main(){

    int N,Q;

    cin >> N >> Q;

    Graph T(N+1,vector<int>(0));

    seen.resize(N+1,false);

    counter.resize(N+1,0);

    ADD.resize(N+1,0);

    rep(i,N-1){

        int a,b;

        cin >> a >> b;

        T[a].push_back(b);

        T[b].push_back(a);

    }

    rep(i,Q){

        ll p,x;

        cin >> p >> x;

        ADD[p]+=x;

    }

    dfs(T,1,ADD[1]);

    rep(i,N)cout << counter[i+1] << " ";

    cout << endl;

    return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < n; ++i)

#define REPP(i, n) for(int i = 1; i <= n; ++i)

#define REPR(i, n) for(int i = n-1; i >= 0; --i)

#define FOR(i, m, n) for(int i = m; i < n; ++i)

#define ALL(v) v.begin(), v.end()

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

const ll MOD = 1000000007;

const ll INF = 1000000000;



vector<int> G[200000];

vector<int> V;



void dfs(int v, int p) {

    for(int u : G[v]) {

        if(u==p) continue;

        V[u] += V[v];

        dfs(u, v);

    }

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n,q; cin >> n >> q;

    REP(i,n-1) {

        int a,b; cin >> a >> b; a--, b--;

        G[a].push_back(b);

        G[b].push_back(a);

    }

    V.resize(n);

    REP(i,q) {

        int p,x; cin >> p >> x; p--;

        V[p] += x;

    }

    dfs(0,-1);

    REP(i,n) {

        if(i==n-1) cout << V[i] << endl;

        else cout << V[i] << " ";

    }

    return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define REP(i, n) for(int i = 0; i < n; ++i)

#define REPP(i, n) for(int i = 1; i <= n; ++i)

#define REPR(i, n) for(int i = n-1; i >= 0; --i)

#define FOR(i, m, n) for(int i = m; i < n; ++i)

#define ALL(v) v.begin(), v.end()

#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

using namespace std;

typedef long long ll;

typedef pair<ll, ll> P;

const ll MOD = 1000000007;

const ll INF = 1000000000;



void dfs(int v, int p, vector<int> &ans, vector<vector<int>> &g) {

    for(int u : g[v]) {

        if(u==p) continue;

        ans[u] += ans[v];

        dfs(u, v, ans, g);

    }

}



int main() {

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n,q; cin >> n >> q;

    vector<vector<int>> g(n);

    REP(i,n-1) {

        int a,b; cin >> a >> b; a--, b--;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    vector<int> ans(n,0);

    REP(i,q) {

        int p,x; cin >> p >> x; p--;

        ans[p] += x;

    }

    dfs(0,-1,ans,g);

    REP(i,n) {

        if(i==n-1) cout << ans[i] << endl;

        else cout << ans[i] << " ";

    }

    return 0;

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



int N, Q;

vector<int> edges[200000];

int64_t num[200000];



void dfs(int i, int p){

    for(int j : edges[i]) if(j != p){

        num[j] += num[i];

        dfs(j, i);

    }

}



int main(){

    cin >> N >> Q;

    for(int i=0; i<N-1; i++){

        int a, b;

        cin >> a >> b;

        edges[a-1].push_back(b-1);

        edges[b-1].push_back(a-1);

    }

    for(int i=0; i<Q; i++){

        int p, x;

        cin >> p >> x;

        num[p-1] += x;

    }

    dfs(0, -1);

    for(int i=0; i<N; i++) cout << num[i] << " \n"[i==N-1];

    return 0;

}


// Optimized solution to the same problem (faster):


#include <stdio.h>

#include <iostream>

#include <string.h>

#include <limits.h>

#include <string>

#include <vector>

#include <algorithm>

#include <map>

#include <set>



#ifndef ULLONG

typedef unsigned long long ULLONG;

#endif

#ifndef LLONG

typedef long long LLONG;

#endif

template <class _T> static _T tp_abs(const _T& a) {

	return ((a < 0) ? (a * -1) : a);

}

template <class _T> static _T tp_min(_T a, _T b) {

	return a < b ? a : b;

}

template <class _T> static _T tp_max(_T a, _T b) {

	return a > b ? a : b;

}

template<class _T> static void get1int(_T& a) {

	const char* fmt = " %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld";

	}



	if (scanf(fmt, &a) < 0) {

		printf("g1int Error\n");

	}

}

template<class _T> static void get2int(_T& a, _T& b) {

	const char* fmt = " %d %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld %lld";

	}



	if (scanf(fmt, &a, &b) < 0) {

		printf("g2int Error\n");

	}

}

template<class _T> static void get3int(_T& a, _T& b, _T& c) {

	const char* fmt = " %d %d %d";

	if (sizeof(_T) == sizeof(long long)) {

		fmt = " %lld %lld %lld";

	}



	if (scanf(fmt, &a, &b, &c) < 0) {

		printf("g3int Error\n");

	}

}

static void getstring(char* buff) {

	if (scanf(" %s", buff) < 0) {

		printf("getstr error!\n");

	}

}

static const long long MOD_NUM = 1000000007LL;



static void D2_task();



int main()

{

	D2_task();

	fflush(stdout);

	return 0;

}



static void D2_dfs(std::vector<std::vector<int>>& graph, std::vector<LLONG>& tree, int now, int par)

{

	for (auto it = graph[now].begin(); it != graph[now].end(); it++) {

		if (*it == par) continue;

		tree[*it] += tree[now];

		D2_dfs(graph, tree, *it, now);

	}

}



static void D2_task()

{

	int N, Q;

	get2int(N, Q);



	std::vector<std::vector<int>> graph(N);

	int a, b;

	for (int i = 0; i < N - 1; i++) {

		get2int(a, b); a--; b--;

		graph[a].push_back(b);

		graph[b].push_back(a);

	}

	

	std::vector<LLONG> tree(N, 0);

	int p, x;

	for (int i = 0; i < Q; i++) {

		get2int(p, x); p--;

		tree[p] += (LLONG)x;

	}



	D2_dfs(graph, tree, 0, -1);



	for (int i = 0; i < N; i++) {

		printf("%lld ", tree[i]);

	}

}


// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;

typedef long long ll;



vector<vector<int>> ki(200002);

vector<int> ans(200002, 0);



void dfs(int v, int p=-1){

	for(int u: ki.at(v)){

		if(u == p) continue;

		ans.at(u) += ans.at(v);

		dfs(u, v);

	}

}



int main() {

	

	int n, q;

	cin >> n >> q;

	

	rep(i, n-1){

		int a, b;

		cin >> a >> b;

		a--;

		b--;

		ki.at(a).push_back(b);

		ki.at(b).push_back(a);

	}

	rep(i, q){

		int p, x;

		cin >> p >> x;

		p--;

		ans.at(p) += x;

	}

	

	dfs(0);

	

	rep(i, n){

		cout << ans.at(i) << " ";

	}

	cout << endl;

	return 0;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

#define rep(i,n) for (int i = 0; i < (n); ++i)

#define all(v) v.begin(), v.end()

using namespace std;

typedef long long ll;



void dfs(vector<vector<int>> &g, int v, int p, vector<int> &c) {

	for(auto next_v: g[v]) {

		if(next_v == p) continue;

		c[next_v] += c[v];

		dfs(g, next_v, v, c);

	}

}



int main() {

	int n, q;

	cin >> n >> q;

	vector<vector<int>> g(n);

	rep(i, n-1) {

		int a, b;

		cin >> a >> b;

		a--; b--;

		g[a].push_back(b);

		g[b].push_back(a);

	}

	vector<int> p(q), x(q), c(n);

	rep(i, q) {

		cin >> p[i] >> x[i];

		p[i]--;

	}

	rep(i, q) {

		c[p[i]] += x[i];

	}

	dfs(g, 0, -1, c);

	rep(i, n) printf("%d%c", c[i], (i == n-1) ? '\n' : ' ');

	return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<iostream>

#include<vector>

#include<string>

#include<cmath>

#include<algorithm>

#include <numeric>

#include<map>

#include<unordered_map>

 

using namespace std;

using ll=long long;

#define rep(i,n) for(int i=0;i<n;i++)

#define all_map(itr,mp) for(auto itr=mp.begin();itr!=mp.end();itr++)

#define ALL(a) (a).begin(),(a).end()



struct tree{

    ll self;

    vector<ll> child;

    ll counter = 0;

};

tree t[200010];

bool visited[200010];

void score(ll c){

    visited[c] = true;

    rep(i, t[c].child.size()){

        ll leaf = t[c].child[i];

        if(visited[leaf])continue;

        t[leaf].counter += t[c].counter;

        score(leaf);

    }

}

int main(){

    ll n, q;

    cin >> n >> q;

    for(int i = 1; i < n; ++i){

        ll a, b;

        cin >> a >> b;

        t[a].child.push_back(b);

        t[b].child.push_back(a);

    }

    rep(i, q){

        ll p, x;

        cin >> p >> x;

        t[p].counter += x;

    }

    rep(i, 200010)visited[i] = false;



    score(1);

    for(int i = 1; i <= n; ++i)cout << t[i].counter << " ";

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

 

#define rep(i,n) for(ll i=0;i<n;++i)

#define ALL(a) (a).begin(),(a).end()

 

using namespace std;

using ll  = long long;

using pll = pair<ll, ll>;

 

const ll MOD  = 1e9+7;

const ll LINF = 1LL << 60;

const int INF = 1e9 + 7;



struct node{

    vector<ll> child;

    ll counter = 0;

};



vector<node> tree(200020);



void dfs(ll crnt_node, ll parent){

    tree[crnt_node].counter += tree[parent].counter;



    rep(i, tree[crnt_node].child.size()){

        ll next_node = tree[crnt_node].child[i];

        if(next_node == parent)continue;

        dfs(next_node, crnt_node);

    }

}



int main(){

    ll n, q;

    cin >> n >> q;



    rep(i, n-1){

        ll a, b;

        cin >> a >> b;

        a--, b--;



        tree[a].child.push_back(b);

        tree[b].child.push_back(a);

    }



    rep(i, q){

        ll p, x;

        cin >> p >> x;

        p--;



        tree[p].counter += x;

    }



    rep(i, tree[0].child.size()){

        ll next_node = tree[0].child[i];

        dfs(next_node, 0);

    }



    rep(i, n)cout << tree[i].counter << " ";

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;



// 隣接行列を用いた幅優先探索 O(|V|^2)

int n;

vector<int> G[200000];

vector<int> d(200000), visited(200000); // 始点sから頂点iまでの最短距離をd[i]に記録

/*

* main関数からこれらを削除すること

* 隣接行列Mの行数と列数および最短距離dの要素数はnの最大値を整数で入力すること

*/



void bfs(int s) {

  queue<int> q;

  q.push(s);

  visited[s] = 1;

  // d[s] = 0;

  while(!q.empty()){

    int u = q.front();

    q.pop();

    for(int v = 0; v < G[u].size(); v++){

      if(visited.at(G[u][v]) == 0){

        d[G[u][v]] += d[u];

        visited.at(G[u][v]) = 1;

        /* if(M[u][v] == 0) continue;

        if(d[v] != 100000000) continue;

        d[v] = d[u] + 1;*/

        q.push(G[u][v]);

      }

    }

  }

}



int main() {

// 無向(有向)グラフの隣接リスト

  int q, u, v, p, x;

  

  cin >> n >> q;

  

  // vector<int> G[n]; // 頂点数がnのグラフを表す隣接リスト

  

  for(int i = 0; i < n - 1; i++){

    cin >> u >> v;

    u--;

    v--;

    G[u].push_back(v);

    G[v].push_back(u); // 有向グラフではこの行をコメントアウト

  }

  

  for(int i = 0; i < q; i++){

    cin >> p >> x;

    d.at(p - 1) += x;

  }

  

  bfs(0);

  

  for(int i = 0; i < n; i++){

    if(i) cout << " ";

    cout << d[i];

  }

  cout << endl;

}

// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



using ll = long long;



void dfs(vector<vector<int>> &G, int x, int p, ll keep, vector<ll> &counter) {

  counter[x] += keep;

  for (int i = 0; i < G[x].size(); i++) {

    if (G[x][i] == p) continue;

    dfs(G, G[x][i], x, counter[x], counter);

  }

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

  

  int n, q;

  cin >> n >> q;

  

  vector<vector<int>> G(n);

  for (int i = 0; i < n - 1; i++) {

    int a, b;

    cin >> a >> b;

    a--;

    b--;

    G[a].push_back(b);

    G[b].push_back(a);

  }

  

  vector<ll> counter(n, 0);

  

  for (int i = 0; i < q; i++) {

    ll p, x;

    cin >> p >> x;

    p--;

    counter[p] += x;

  }

  

  dfs(G, 0, -1, 0, counter);

  

  for (int i = 0; i < n; i++) {

    if (i) cout << " ";

    cout << counter[i];

  }

  cout << '\n';

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
// 嘘解法か判断する用

#include <bits/stdc++.h>

using namespace std;



// 隣接行列を用いた幅優先探索 O(|V|^2)

int n;

vector<int> G[200000];

vector<int> d(200000), visited(200000); // 始点sから頂点iまでの最短距離をd[i]に記録

/*

* main関数からこれらを削除すること

* 隣接行列Mの行数と列数および最短距離dの要素数はnの最大値を整数で入力すること

*/



void bfs(int s) {

  queue<int> q;

  q.push(s);

  visited[s] = 1;

  // d[s] = 0;

  while(!q.empty()){

    int u = q.front();

    q.pop();

    for(int v = 0; v < G[u].size(); v++){

      if(visited.at(G[u][v]) == 0){

        d[G[u][v]] += d[u];

        visited.at(G[u][v]) = 1;

        /* if(M[u][v] == 0) continue;

        if(d[v] != 100000000) continue;

        d[v] = d[u] + 1;*/

        q.push(G[u][v]);

      }

    }

  }

}



int main() {

// 無向(有向)グラフの隣接リスト

  int q, u, v, p, x;

  

  cin >> n >> q;

  

  // vector<int> G[n]; // 頂点数がnのグラフを表す隣接リスト

  

  for(int i = 0; i < n - 1; i++){

    cin >> u >> v;

    u--;

    v--;

    G[u].push_back(v);

    G[v].push_back(u); // 有向グラフではこの行をコメントアウト

  }

  

  for(int i = 0; i < q; i++){

    cin >> p >> x;

    d.at(p - 1) += x;

  }

  

  bfs(0);

  

  for(int i = 0; i < n; i++){

    if(i) cout << " ";

    cout << d[i];

  }

  cout << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;



using ll = long long;



void dfs(vector<vector<int>> &G, int x, int p, ll keep, vector<ll> &counter) {

  counter[x] += keep;

  for (int i = 0; i < G[x].size(); i++) {

    if (G[x][i] == p) continue;

    dfs(G, G[x][i], x, counter[x], counter);

  }

}



int main() {

  cin.tie(0);

  ios::sync_with_stdio(false);

  

  int n, q;

  cin >> n >> q;

  

  vector<vector<int>> G(n);

  for (int i = 0; i < n - 1; i++) {

    int a, b;

    cin >> a >> b;

    a--;

    b--;

    G[a].push_back(b);

    G[b].push_back(a);

  }

  

  vector<ll> counter(n, 0);

  

  for (int i = 0; i < q; i++) {

    ll p, x;

    cin >> p >> x;

    p--;

    counter[p] += x;

  }

  

  dfs(G, 0, -1, 0, counter);

  

  for (int i = 0; i < n; i++) {

    if (i) cout << " ";

    cout << counter[i];

  }

  cout << '\n';

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include <bits/stdc++.h>

using namespace std;

 

typedef long long ll;

typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

 

template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}

template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}



const int NM = 2*1e5;

vector<int> graph[NM]; 

vector<int> Count(NM);

int n, q; 

void dfs(int now, int pre) {

    for(auto to : graph[now]) {

        if(to == pre) continue;

        Count[to] += Count[now];

        dfs(to, now);

    }

}

int main(){

    cin >> n >> q;

    for(int i=0; i<n-1;i++) {

        int a, b; cin >> a >> b;

        a--; b--;

        graph[a].push_back(b);

        graph[b].push_back(a);

    }

    Count.resize(n);

    rep(i, q) {

        int p, x; cin>>p>> x;

        p--;

        Count[p] += x;

    }

    dfs(0, -1);

    rep(i, n) {

        cout << Count[i] << ' ';

    }

    cout << endl;

}


// Optimized solution to the same problem (faster):
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

typedef pair<int, int> P;

#define rep(i, n) for (int i = 0; i < (int)(n); ++i)

template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}

template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}



const int NM = 2*1e5+10;

int ans[NM];

vector<vector<int>> g(NM);



void dfs(int now, int prev){

    ans[now] += ans[prev];

    for(auto next : g[now]){

        if(next == prev) continue;

        dfs(next, now);

    }

}



int main(){

    cin.tie(0);

    ios::sync_with_stdio(false);

    int n, q; cin>>n>>q;

    for(int i=1; i<=n-1; i++){

        int a, b; cin>>a>>b;

        g[a].push_back(b);

        g[b].push_back(a);

    }

    for(int i=1; i<=q; i++){

        int p, x; cin >> p>>x;

        ans[p] += x;

    }

    dfs(1, 0);

    for(int i=1;i<=n;i++){

        cout << ans[i] <<" ";

    }

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<list>

#include<iostream>

using namespace std;

int main(){

  int i;

  int n;

  long long c;

  for(;;){

    cin>>n;

    if(n==0)

      break;

    list<int> t;

    c=0;

    for(i=0;i<n;i++){

      int tmp;

      cin>>tmp;

      t.push_back(tmp);

    }

    t.sort();

    list<int>::iterator it=t.begin();

    for(i=0;i<n-1;i++){

      c+=(*it)*(n-i-1);

      it++;

    }

    cout<<c<<endl;

  }

  return 0;

}

// Optimized solution to the same problem (faster):
#include<algorithm>

#include<cstdio>

using namespace std;

int main(){

  int i;

  int n;

  while(scanf("%d",&n),n){

    int a[10000];

    for(i=0;i<n;++i)

      scanf("%d",a+i);

    sort(a,a+n);

    long long sm=0;

    for(i=0;i<n-1;++i)

      sm+=a[i]*(n-i-1);

    printf("%lld\n",sm);

  }

  return 0;

}

// Fastest known solution for this problem:
// Original C++ solution (slower):
#include<bits/stdc++.h>

using namespace std;

const int maxn=2e5+10;

vector<int>G[maxn];

int in[maxn],out[maxn],tol;

int sz[maxn],S[maxn],is[maxn],son[maxn];

void get_cal(int v,int fa,int limit)

{

	son[v]=0;

	if(v>=limit)

		return;

	son[v]=1;

	for(int i=G[v].size()-1;i>=0;i--)

	{

		int u=G[v][i];

		if(u==fa)

			continue;

		get_cal(u,v,limit);

		son[v]+=son[u];

	}

}

void get_order(int v,int fa,int mx)

{

	is[v]=mx;

	for(int i=G[v].size()-1;i>=0;i--)

	{

		int u=G[v][i];

		if(u==fa)

			continue;

		if(is[v]>is[fa]||v>is[v])

			get_cal(u,v,is[v]);

		sz[u]=son[u];

	}

	for(int i=G[v].size()-1;i>=0;i--)

	{

		int u=G[v][i];

		if(u==fa)

			continue;

		get_order(u,v,max(mx,v));

	}

}

void dfs(int v,int fa)

{

	S[v]++;

	for(int i=G[v].size()-1;i>=0;i--)

	{

		int u=G[v][i];

		if(u==fa)

			continue;

		S[v]+=sz[u];

	}

	for(int i=G[v].size()-1;i>=0;i--)

	{

		int u=G[v][i];

		if(u==fa)

			continue;

		S[u]=S[v]-sz[u];

		dfs(u,v);

	}

}

int main()

{

	int n;scanf("%d",&n);

	for(int i=1;i<n;i++)

	{

		int x,y;scanf("%d%d",&x,&y);

		G[x].push_back(y);

		G[y].push_back(x);

	}

	get_order(1,0,0);

	dfs(1,0);

	for(int i=2;i<=n;i++)

		printf("%d ",S[i]-1);

	return 0;

}


// Optimized solution to the same problem (faster):
#include<cstdio>

#include<queue>

using namespace std;

#define N 200050

int fa[N],sz[N],head[N],cnt,mx[N],f[N],ti=1,as[N],n,a,b,fr[N],vl[N];

struct edge{int t,next;}ed[N*2];

priority_queue<pair<int,int> > st;

int finds(int x){return fa[x]==x?x:fa[x]=finds(fa[x]);}

void adde(int f,int t){ed[++cnt]=(edge){t,head[f]};head[f]=cnt;ed[++cnt]=(edge){f,head[t]};head[t]=cnt;}

void dfs1(int u,int fa){f[u]=fa;mx[u]=mx[f[u]],fr[u]=fr[f[u]];if(mx[u]<fa)mx[u]=fa,fr[u]=u;for(int i=head[u];i;i=ed[i].next)if(ed[i].t!=fa)dfs1(ed[i].t,u);}

int que(int x){if(x<ti)return sz[finds(x)]-1;int as=0;for(int i=head[x];i;i=ed[i].next)if(ed[i].t<ti)as+=sz[finds(ed[i].t)];return as;}

int main()

{

	scanf("%d",&n);

	for(int i=1;i<n;i++)scanf("%d%d",&a,&b),adde(a,b);

	for(int i=1;i<=n;i++)fa[i]=i,sz[i]=1;

	dfs1(1,0);

	for(int i=head[1];i;i=ed[i].next)st.push(make_pair(-1,ed[i].t));

	while(!st.empty())

	{

		int las=ti;

		ti=-st.top().first;int s=st.top().second;st.pop();

		for(int i=las;i<ti;i++)

		for(int j=head[i];j;j=ed[j].next)if(ed[j].t<i){int a=finds(i),b=finds(ed[j].t);fa[a]=b,sz[b]+=sz[a];}

		as[s]+=as[mx[s]]+que(s)+1-vl[fr[s]];

		for(int i=head[s];i;i=ed[i].next)if(ed[i].t!=f[s])st.push(make_pair(-mx[ed[i].t],ed[i].t)),vl[ed[i].t]=ed[i].t<ti?sz[finds(ed[i].t)]:0;

	}

	for(int i=2;i<=n;i++)printf("%d ",as[i]);

}//

// Fastest known solution for this problem: