func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 3e5 + 7;   const int inf = 0x3f3f3f3f;   const long long INF = 0x3f3f3f3f3f3f3f3f;   const int mod = 1e9 + 7;   const double eps = 1e-8;   const double PI = acos(-1);   template <class T, class S>   inline void add(T &a, S b) {     a += b;     if (a >= mod) a -= mod;   }   template <class T, class S>   inline void sub(T &a, S b) {     a -= b;     if (a < 0) a += mod;   }   template <class T, class S>   inline bool chkmax(T &a, S b) {     return a < b ? a = b, true : false;   }   template <class T, class S>   inline bool chkmin(T &a, S b) {     return a > b ? a = b, true : false;   }   mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());   int n;   long long dp[N];   long long w[N];   long long ans;   vector<pair<long long, int> > G[N];   void dfs(int u, int fa) {     vector<long long> V;     for (auto &e : G[u]) {       int v = e.second;       long long w = e.first;       if (v == fa) continue;       dfs(v, u);       if (dp[v] - e.first > 0) V.push_back(dp[v] - e.first);     }     sort(V.rbegin(), V.rend());     if (((int)V.size()) >= 2) {       chkmax(ans, V[0] + V[1] + w[u]);       dp[u] = V[0] + w[u];     } else if (((int)V.size()) >= 1) {       chkmax(ans, V[0] + w[u]);       dp[u] = V[0] + w[u];     } else {       chkmax(ans, w[u]);       dp[u] = w[u];     }   }   int main() {     scanf( %d , &n);     for (int i = 1; i <= n; i++) {       scanf( %lld , &w[i]);     }     for (int i = 1; i < n; i++) {       int u, v, c;       scanf( %d%d%d , &u, &v, &c);       G[u].push_back(make_pair(c, v));       G[v].push_back(make_pair(c, u));     }     dfs(1, 0);     printf( %lld n , ans);     return 0;   }   