func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long N = 5e5 + 7;   const long long INF = 1e17 + 7;   long long h[N], t[N], f[N][2], pos[N], w[N];   long long n, num = 0;   struct edge {     long long v, next;   } e[N * 2];   struct pir {     long long a, b;   } p[N];   bool cmp(pir x, pir y) { return (x.b - x.a) < (y.b - y.a); }   void add(long long x, long long y) {     e[num] = (edge){y, pos[x]};     pos[x] = num++;   }   void dfs(long long x, long long fa) {     long long cnt = 0, s1 = 0, s0 = 0, hh = 0, ss = 0;     for (long long i = pos[x]; ~i; i = e[i].next) {       if (e[i].v == fa) continue;       hh = 1;       dfs(e[i].v, x);       if (h[e[i].v] > h[x]) s1++, ss += f[e[i].v][1];       if (h[e[i].v] < h[x]) s0++, ss += f[e[i].v][0];     }     if (!hh) {       f[x][0] = f[x][1] = t[x];       return;     }     w[0] = 0;     for (long long i = pos[x]; ~i; i = e[i].next) {       if (e[i].v != fa && h[e[i].v] == h[x]) {         w[0] += f[e[i].v][0];         p[++cnt] = (pir){f[e[i].v][0], f[e[i].v][1]};       }     }     sort(p + 1, p + cnt + 1, cmp);     for (long long i = 1; i <= cnt; i++) w[i] = w[i - 1] + p[i].b - p[i].a;     f[x][0] = f[x][1] = INF;     for (long long i = 0; i <= cnt + 1 - 1; i++) {       f[x][0] =           min(f[x][0], w[i] + max(cnt - i + s0, i + s1 + (x != 1)) * t[x] + ss);       f[x][1] =           min(f[x][1], w[i] + max(cnt - i + s0 + (x != 1), i + s1) * t[x] + ss);     }   }   int main() {     scanf( %I64d , &n);     memset(pos, -1, sizeof(pos));     for (long long i = 1; i <= n; i++) scanf( %I64d , &t[i]);     for (long long i = 1; i <= n; i++) scanf( %I64d , &h[i]);     for (long long i = 1; i <= n - 1; i++) {       long long x, y;       scanf( %I64d%I64d , &x, &y);       add(x, y);       add(y, x);     }     dfs(1, 0);     printf( %I64d n , f[1][0]);     return 0;   }   