func_code_string: #include <bits/stdc++.h>   using namespace std;   const int MAX = 2e5 + 5;   int parent[MAX];   int depth[MAX];   int get(int a) {     while (a != parent[a]) a = parent[a];     return a;   }   void join(int a, int b) {     a = get(a);     b = get(b);     if (a == b) return;     if (depth[a] > depth[b]) swap(a, b);     parent[a] = b;     depth[b] += depth[a];   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     int n, q, a, b, w;     cin >> n >> q;     for (int i = 1; i <= n + 1; i++) {       parent[i] = i;       depth[i] = 1;     }     vector<pair<int, pair<int, int>>> vp;     vector<long long> sol(MAX);     long long cnt = 0;     for (int i = 0; i < n - 1; i++) {       cin >> a >> b >> w;       vp.push_back({w, {a, b}});     }     sort(vp.begin(), vp.end());     reverse(vp.begin(), vp.end());     for (int j = 1; j < MAX; j++) {       while (!vp.empty() && vp.back().first <= j) {         a = vp.back().second.first;         b = vp.back().second.second;         vp.pop_back();         a = get(a);         b = get(b);         if (a == b) continue;         cnt -= 1ll * depth[a] * (depth[a] - 1) / 2;         cnt -= 1ll * depth[b] * (depth[b] - 1) / 2;         join(a, b);         a = get(a);         cnt += 1ll * depth[a] * (depth[a] - 1) / 2;       }       sol[j] = cnt;     }     while (q--) {       cin >> w;       cout << sol[w] <<    ;     }     cout <<   n ;     return 0;   }   