func_code_string: #include <bits/stdc++.h>   using namespace std;   const int maxn = 5e3 + 10, INF = 0x3f3f3f3f;   struct edge {     int x;     int y;   } e[maxn];   int w[maxn][maxn];   int num[maxn];   vector<int> vec[maxn];   int depth[maxn];   int fa[maxn];   void dfs(int cur, int p, int dep) {     fa[cur] = p;     depth[cur] = dep;     for (int x : vec[cur]) {       if (x != p) {         dfs(x, cur, dep + 1);       }     }     num[cur] = INF;   }   bool lca_modify(int x, int y, int k) {     int minn = INF;     if (depth[x] < depth[y]) swap(x, y);     while (depth[x] != depth[y]) {       if (num[x] == INF) {         num[x] = k;         w[x][fa[x]] = w[fa[x]][x] = k;       }       minn = min(minn, num[x]);       x = fa[x];     }     while (x != y) {       if (num[x] == INF) {         num[x] = k;         w[x][fa[x]] = w[fa[x]][x] = k;       }       minn = min(minn, num[x]);       x = fa[x];       if (num[y] == INF) {         num[y] = k;         w[y][fa[y]] = w[fa[y]][y] = k;       }       minn = min(minn, num[y]);       y = fa[y];     }     return minn == k;   }   const int maxm = 5e3 + 10;   struct query {     int x, y, len;   } q[maxm];   bool cmp(query a, query b) { return a.len > b.len; }   int main() {     int n, m;     cin >> n;     for (int i = 0; i < n - 1; i++) {       int x, y;       cin >> x >> y;       e[i].x = x, e[i].y = y;       vec[x].push_back(y);       vec[y].push_back(x);     }     dfs(1, 0, 1);     cin >> m;     int x, y, len;     for (int i = 1; i <= m; i++) {       cin >> x >> y >> len;       q[i].x = x, q[i].y = y, q[i].len = len;     }     sort(q + 1, q + 1 + m, cmp);     int flag = 1;     for (int i = 1; i <= m; i++) {       x = q[i].x, y = q[i].y, len = q[i].len;       if (lca_modify(x, y, len) == false) {         flag = 0;         break;       }     }     if (!flag) {       cout << -1 << endl;     } else {       for (int i = 0; i < n - 1; i++) {         x = e[i].x, y = e[i].y;         if (x > y) swap(x, y);         if (w[x][y] == 0)           cout << 1000000;         else           cout << w[x][y];         if (i != n - 2)           cout <<    ;         else           cout << endl;       }     }     return 0;   }   