func_code_string: #include <bits/stdc++.h>   using namespace std;   const int M = 200010;   int par[M];   int sz[M];   struct edge {     int u, v, w;     bool operator<(const edge &e) const { return w < e.w; }   };   edge E[M];   pair<int, int> q[M];   long long out[M];   int f(int u) { return par[u] = par[u] == u ? u : f(par[u]); }   int add(int u, int v) {     u = f(u);     v = f(v);     if (u == v) return 0;     par[v] = u;     sz[u] += sz[v];     return sz[u];   }   long long get(int n) {     if (n <= 0) return 0;     return ((long long)n * (long long)(n - 1)) / 2;   }   int main() {     ios_base::sync_with_stdio(false);     int n, m;     cin >> n >> m;     for (int i = 0; i < n - 1; i++) {       cin >> E[i].u >> E[i].v >> E[i].w;     }     for (int i = 0; i < m; i++) {       cin >> q[i].first;       q[i].second = i;     }     sort(E, E + n - 1);     sort(q, q + m);     for (int i = 1; i <= n; i++) par[i] = i, sz[i] = 1;     long long ans = 0;     int j = 0;     for (int i = 0; i < m; i++) {       while (j < n - 1) {         if (E[j].w > q[i].first) break;         int u = f(E[j].u), v = f(E[j].v);         ans -= (get(sz[u]) + get(sz[v]));         ans += get(add(u, v));         j++;       }       out[q[i].second] = ans;     }     for (int i = 0; i < m; i++) cout << out[i] <<    ;     cout << endl;     return 0;   }   