func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 100005;   int n, a, b, q, p[N], d[N];   vector<pair<int, int> > g[N];   int dp[N][17], v, ud[N], ans[N];   bool vis[N];   void dfs(int u) {     vis[u] = 1;     for (int i = 0; i < (int)g[u].size(); ++i) {       v = g[u][i].first;       if (!vis[v]) {         p[v] = u;         d[v] = d[u] + 1;         dfs(v);       }     }   }   int lca(int a, int b) {     if (d[a] < d[b]) swap(a, b);     int log = 0;     for (; (1 << log) <= d[a]; ++log)       ;     --log;     for (int i = log; i >= 0; --i) {       if (d[a] - (1 << i) >= d[b]) a = dp[a][i];     }     if (a == b) return a;     for (int i = log; i >= 0; --i) {       if (dp[a][i] != dp[b][i]) {         a = dp[a][i];         b = dp[b][i];       }     }     return p[a];   }   int DFS(int u) {     vis[u] = 1;     for (int i = 0; i < (int)g[u].size(); ++i) {       int v = g[u][i].first;       if (!vis[v]) {         ud[u] += DFS(v);         ans[g[u][i].second] = ud[v];       }     }     return ud[u];   }   int main(int argc, char **argv) {     scanf( %d , &n);     for (int i = 1; i < n; ++i) {       scanf( %d%d , &a, &b);       g[a].push_back(make_pair(b, i));       g[b].push_back(make_pair(a, i));     }     memset(p, -1, sizeof p);     memset(dp, -1, sizeof dp);     dfs(1);     for (int i = 0; i <= n; ++i) dp[i][0] = p[i];     for (int j = 1; (1 << j) <= n; ++j) {       for (int i = 0; i <= n; ++i) {         if (dp[i][j - 1] != -1) dp[i][j] = dp[dp[i][j - 1]][j - 1];       }     }     scanf( %d , &q);     int LCA;     while (q--) {       scanf( %d%d , &a, &b);       LCA = lca(a, b);       ++ud[a], ++ud[b], ud[LCA] -= 2;     }     memset(vis, 0, sizeof vis);     DFS(1);     for (int i = 1; i < n; ++i) {       if (i > 1) printf(   );       printf( %d , ans[i]);     }     puts(  );     return 0;   }   