func_code_string: #include <bits/stdc++.h>   using namespace std;   int main() {     ios::sync_with_stdio(false);     int n, u, v, c, a, b, t;     cin >> n;     long long w[n], A, B, Su[n], SMax = 0;     int g[n], S[n], Pa[n];     vector<pair<int, long long>> D[n];     vector<int> T, P;     for (int i = 0; i < n; i++) {       cin >> w[i];       g[i] = 1;     }     for (int i = 0; i < n - 1; i++) {       cin >> u >> v >> c;       u--;       v--;       D[u].push_back({v, c});       D[v].push_back({u, c});     }     g[0] = 0;     T.push_back(0);     for (int i = 0; i < T.size(); i++) {       t = 0;       for (int y = 0; y < D[T[i]].size(); y++) {         a = D[T[i]][y].first;         if (g[a] == 1) {           Pa[a] = T[i];           g[a] = 0;           t = 1;           T.push_back(a);         }       }       if (t == 0) {         P.push_back(T[i]);       }     }     T.clear();     for (int i = 0; i < n; i++) {       g[i] = 1;       S[i] = D[i].size() - 1;       if (i == 0) {         S[i]++;       }     }     for (int i = 0; i < P.size(); i++) {       g[P[i]] = 0;       a = P[i];       if (a != 0) {         S[Pa[a]]--;         if (S[Pa[a]] == 0) {           P.push_back(Pa[a]);         }       }       A = 0;       B = 0;       for (int y = 0; y < D[a].size(); y++) {         b = D[a][y].first;         c = D[a][y].second;         if (b != Pa[a]) {           if (Su[b] - c + w[b] > A) {             B = A;             A = Su[b] - c + w[b];           } else if (Su[b] - c + w[b] > B) {             B = Su[b] - c + w[b];           }         }       }       SMax = max(SMax, A + B + w[a]);       Su[a] = A;     }     cout << SMax;     return 0;   }   