func_code_string: #include <bits/stdc++.h>   int min(int a, int b) { return a < b ? a : b; }   int max(int a, int b) { return a > b ? a : b; }   unsigned int X;   void srand_() {     struct timeval tv;     gettimeofday(&tv, NULL);     X = tv.tv_sec ^ tv.tv_usec | 1;   }   int rand_() { return (X *= 3) >> 1; }   int *ej[1000], eo[1000];   void append(int i, int j) {     int o = eo[i]++;     if (o >= 2 && (o & o - 1) == 0)       ej[i] = (int *)realloc(ej[i], o * 2 * sizeof *ej[i]);     ej[i][o] = j;   }   int aa[1000], bb[1000], ii[1000], n;   int compare(int i, int j) { return aa[i] != aa[j] ? aa[i] - aa[j] : i - j; }   void sort(int *ii, int l, int r) {     while (l < r) {       int i = l, j = l, k = r, i_ = ii[l + rand_() % (r - l)], tmp;       while (j < k) {         int c = compare(ii[j], i_);         if (c == 0)           j++;         else if (c < 0) {           tmp = ii[i], ii[i] = ii[j], ii[j] = tmp;           i++, j++;         } else {           k--;           tmp = ii[j], ii[j] = ii[k], ii[k] = tmp;         }       }       sort(ii, l, i);       l = k;     }   }   char visited[1000];   int qu[1000], cnt;   int i_;   void dfs1(int i) {     int o;     if (visited[i] || compare(i, i_) > 0) return;     visited[i] = 1;     qu[cnt++] = i;     for (o = eo[i]; o--;) {       int j = ej[i][o];       dfs1(j);     }   }   char add[1000];   int cc[1000][1000];   void dfs2(int p, int i, int c) {     int o;     for (o = eo[i]; o--;) {       int j = ej[i][o];       if (j != p) {         if (compare(j, i_) > 0)           cc[i_][j] = max(cc[i_][j], c);         else           dfs2(i, j, min(c + bb[j], 0x3f3f3f3f));       }     }   }   int dp[1000];   int solve(int s) {     int g;     memset(dp, 0, n * sizeof *dp), dp[0] = s;     for (g = 0; g < n; g++) {       int i_ = ii[g], x = dp[i_], j;       if (x == 0) continue;       for (j = 0; j < n; j++)         if (compare(i_, j) < 0 && cc[i_][j] != -1) {           int c = add[i_] ? min(x + cc[i_][j], 0x3f3f3f3f)                           : min(s + cc[i_][j], 0x3f3f3f3f);           if (c >= aa[j]) dp[j] = max(dp[j], min(c + bb[j], 0x3f3f3f3f));         }     }     return dp[ii[n - 1]] > 0;   }   int main() {     int t;     srand_();     scanf( %d , &t);     while (t--) {       static int qu_[1000], dd[1000], pp[1000];       int m, g, h, i, j, o, cnt_, lower, upper;       scanf( %d%d , &n, &m);       aa[0] = 0;       for (i = 1; i < n; i++) scanf( %d , &aa[i]), aa[i]++;       for (i = 1; i < n; i++) scanf( %d , &bb[i]);       for (i = 0; i < n; i++) ej[i] = (int *)malloc(2 * sizeof *ej[i]), eo[i] = 0;       for (h = 0; h < m; h++) {         scanf( %d%d , &i, &j), i--, j--;         append(i, j), append(j, i);       }       for (i = 0; i < n; i++) ii[i] = i;       sort(ii, 0, n);       for (g = 0; g < n; g++) {         i_ = ii[g];         memset(visited, 0, n * sizeof *visited), cnt = 0;         memset(cc[i_], -1, n * sizeof *cc[i_]);         dfs1(0);         if (visited[i_]) {           int tree, p;           memset(dd, 0, n * sizeof *dd);           memset(pp, -1, n * sizeof *pp);           for (h = 0; h < cnt; h++) {             i = qu[h];             for (o = eo[i]; o--;) {               j = ej[i][o];               if (visited[j]) dd[i]++;             }           }           cnt_ = 0;           for (h = 0; h < cnt; h++) {             i = qu[h];             if (dd[i] == 1) qu_[cnt_++] = i;           }           while (cnt_) {             i = qu_[--cnt_];             dd[i] = -1;             for (o = eo[i]; o--;) {               j = ej[i][o];               if (dd[j] > 0) {                 pp[i] = j;                 if (--dd[j] == 1) qu_[cnt_++] = j;               }             }           }           tree = 1;           for (h = 0; h < cnt; h++) {             i = qu[h];             if (dd[i] > 0) {               tree = 0;               break;             }           }           p = -1, i = 0;           while (i != -1 && dd[i] <= 0 && i != i_) p = i, i = pp[i];           add[i_] = 1;           if (dd[i_] <= 0 && i != i_)             dfs2(pp[i_], i_, 0);           else if (tree)             dfs2(p, i_, 0);           else {             int c;             add[i_] = 0;             c = 0;             for (i = 0; i != -1 && dd[i] <= 0; i = pp[i])               c = min(c + bb[i], 0x3f3f3f3f);             for (h = 0; h < cnt; h++) {               i = qu[h];               if (dd[i] > 0) c = min(c + bb[i], 0x3f3f3f3f);             }             for (p = -1, i = 0; i != -1 && dd[i] <= 0; p = i, i = pp[i])               for (o = eo[i]; o--;) {                 j = ej[i][o];                 if (compare(j, i_) > 0)                   cc[i_][j] = max(cc[i_][j], c);                 else if (j != pp[i] && j != p)                   dfs2(i, j, min(c + bb[j], 0x3f3f3f3f));               }             for (h = 0; h < cnt; h++) {               i = qu[h];               if (dd[i] > 0)                 for (o = eo[i]; o--;) {                   j = ej[i][o];                   if (compare(j, i_) > 0)                     cc[i_][j] = max(cc[i_][j], c);                   else if (pp[j] == i && j != p)                     dfs2(i, j, min(c + bb[j], 0x3f3f3f3f));                 }             }           }         }       }       lower = 0, upper = 0x3f3f3f3f;       while (upper - lower > 1) {         int s = (lower + upper) / 2;         if (solve(s))           upper = s;         else           lower = s;       }       printf( %d n , upper);       for (i = 0; i < n; i++) free(ej[i]);     }     return 0;   }   