func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long MOD = 1e9 + 7;   const int INF = 0x3f3f3f3f;   const long long INFLL = 0x3f3f3f3f3f3f3f3f;   const int maxn = 1e6 + 10;   struct Edge {     int to, nxt;     long long cost;     Edge() {}     Edge(int to, int nxt, long long cost) : to(to), nxt(nxt), cost(cost) {}   } edge[maxn << 1];   int head[maxn], tot;   long long dp[maxn];   void Init(int n) {     tot = 0;     for (int i = 1; i <= n; ++i) head[i] = -1;   }   void addedge(int u, int v, long long cost) {     edge[tot] = Edge(v, head[u], cost);     head[u] = tot++;     edge[tot] = Edge(u, head[v], cost);     head[v] = tot++;   }   int n;   long long val[maxn];   long long ans;   void DFS(int u, int pre) {     dp[u] = val[u];     long long max1 = 0, max2 = 0;     for (int i = head[u]; ~i; i = edge[i].nxt) {       int v = edge[i].to;       long long cost = edge[i].cost;       if (v == pre) continue;       DFS(v, u);       long long tmp = dp[v] - cost;       if (tmp > max1) swap(max1, tmp);       max2 = max(tmp, max2);       dp[u] = max(dp[u], dp[v] - cost + val[u]);     }     ans = max(ans, max(dp[u], max1 + max2 + val[u]));   }   void RUN() {     while (~scanf( %d , &n)) {       Init(n);       for (int i = 1; i <= n; ++i) scanf( %lld , val + i);       long long w;       for (int i = 1, u, v; i < n; ++i) {         scanf( %d %d %lld , &u, &v, &w);         addedge(u, v, w);       }       ans = 0;       DFS(1, -1);       printf( %lld n , ans);     }   }   int main() {     RUN();     return 0;   }   