#include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5;   int n, a[N], fa[N], head[N], p, deep[N];   long long Chuan1[N], Chuan2[N], Ans;   queue<int> q;   struct wfh {     int to, last;   } d[N << 1];   inline void add(int a, int b) { d[++p] = (wfh){b, head[a]}, head[a] = p; }   inline long long max(long long A, long long B) { return A > B ? A : B; }   inline long long min(long long A, long long B) { return A < B ? A : B; }   void dfs(int u, int fa) {     for (int i = head[u], v; i; i = d[i].last) {       v = d[i].to;       if (v == fa) continue;       dfs(v, u);       Chuan1[u] = max(Chuan1[u], Chuan1[v]);       Chuan2[u] = max(Chuan2[u], Chuan2[v]);     }     a[u] += Chuan2[u] - Chuan1[u];     if (a[u] >= 0)       Chuan1[u] += a[u];     else       Chuan2[u] -= a[u];   }   int main() {     scanf( %d , &n);     for (int i = 1, u, v; i < n; i++) scanf( %d%d , &u, &v), add(u, v), add(v, u);     for (int i = 1; i <= n; i++) scanf( %d , &a[i]);     dfs(1, -1);     printf( %lld n , Chuan1[1] + Chuan2[1]);     return 0;   }   