func_code_string: #include <bits/stdc++.h>   #include <unordered_map>   #include <unordered_set>   using namespace std;   #define endl   n    #define ll long long   #define sz(s) (int)(s.size())   #define INF 0x3f3f3f3f3f3f3f3fLL   #define all(v) v.begin(),v.end()   #define watch(x) cout<<(#x)<<  =  <<x<<endl   const int dr[] { -1, -1, 0, 1, 1, 1, 0, -1 };   const int dc[] { 0, 1, 1, 1, 0, -1, -1, -1 };   #if __cplusplus >= 201402L   template<typename T>   vector<T> create(size_t n) {    return vector<T>(n);   }   template<typename T, typename ... Args>   auto create(size_t n, Args ... args) {    return vector<decltype(create<T>(args...))>(n, create<T>(args...));   }   #endif   void run() {    ios::sync_with_stdio(false);    cin.tie(NULL);    cout.tie(NULL);   #ifndef ONLINE_JUDGE    freopen( input.in ,  r , stdin);   #else    //freopen( groups.in ,  r , stdin);   #endif   }   const int N = 1e5 + 9;   int l[N], r[N];   ll dp[N][2];   vector<vector<int>> adj;   ll dfs(int node, int par, bool b) {    ll &rt = dp[node][b];    if (~rt)     return rt;    rt = 0;    int myVal = (b ? r[node] : l[node]);    for (int ch : adj[node])     if (ch != par)      rt += max(dfs(ch, node, 0) + abs(l[ch] - myVal),        dfs(ch, node, 1) + abs(r[ch] - myVal));    return rt;   }      int main() {    run();    int T;    cin >> T;    while (T--) {     int n;     cin >> n;     memset(dp, -1, (sizeof dp[0]) * (n + 1));     for (int i = 1; i <= n; i++)      cin >> l[i] >> r[i];     adj = vector<vector<int>>(n + 1);     for (int i = 1; i < n; i++) {      int u, v;      cin >> u >> v;      adj[u].push_back(v);      adj[v].push_back(u);     }     cout << max(dfs(1, -1, 0), dfs(1, -1, 1)) << endl;    }   }   