func_code_string: #include <bits/stdc++.h>   using namespace std;   template <class T>   T Max(const T &a, const T &b) {     return a > b ? a : b;   }   const int SN = 100000 + 10;   long long w[SN], f[SN][2], down[SN], g[SN], h[SN], head[SN];   long long u, v, n, num;   bool vis[SN];   struct Edge {     int from, to, next;   } E[SN << 2];   void Read(long long &x) {     long long in = 0, f = 1;     char ch = getchar();     while (ch <  0  || ch >  9 ) {       if (ch =  - ) f = -1;       ch = getchar();     }     while (ch >=  0  && ch <=  9 ) {       in = in * 10 + ch -  0 ;       ch = getchar();     }     x = in * f;   }   void Add(int u, int v) {     E[++num].from = u;     E[num].to = v;     E[num].next = head[u];     head[u] = num;   }   void dfs(int u) {     vis[u] = 1;     g[u] = f[u][0] = f[u][1] = down[u] = w[u];     for (int i = head[u]; i; i = E[i].next) {       int to = E[i].to;       if (vis[to]) continue;       dfs(to);       f[u][0] = Max(f[u][0], f[to][0]);       f[u][0] = Max(f[u][0], f[u][1] + f[to][1]);       f[u][0] = Max(f[u][0], g[to] + down[u]);       f[u][0] = Max(f[u][0], down[to] + g[u]);       f[u][1] = Max(f[u][1], f[to][1]);       f[u][1] = Max(f[u][1], down[u] + down[to]);       g[u] = Max(g[u], g[to] + w[u]);       g[u] = Max(g[u], down[u] + f[to][1]);       g[u] = Max(g[u], down[to] + w[u] + h[u]);       h[u] = Max(h[u], f[to][1]);       down[u] = Max(down[u], down[to] + w[u]);     }   }   int main() {     Read(n);     for (int i = 1; i <= n; i++) Read(w[i]);     for (int i = 1; i < n; i++) {       Read(u), Read(v);       Add(u, v), Add(v, u);     }     dfs(1);     printf( %lld n , f[1][0]);     return 0;   }   