#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 10;
const int oo = 1e9;
int S, T;
struct MCMF {
  const static int M = N * 20;
  int Begin[N], Next[M], to[M], flow[M], cost[M], e;
  MCMF() { e = 1; }
  void add(int u, int v, int f, int c) {
    to[++e] = v, Next[e] = Begin[u], Begin[u] = e, flow[e] = f, cost[e] = c;
    to[++e] = u, Next[e] = Begin[v], Begin[v] = e, flow[e] = 0, cost[e] = -c;
  }
  int dis[N], pre[N];
  bool inq[N];
  bool SPFA(int &sumf, int &sumc) {
    for (int i = 1; i <= T; i++) dis[i] = oo;
    queue<int> q;
    q.push(S);
    dis[S] = 0, q.push(S), inq[S] = true;
    while (!q.empty()) {
      int o = q.front();
      q.pop();
      inq[o] = false;
      for (int i = Begin[o]; i; i = Next[i]) {
        int u = to[i];
        if (!flow[i]) continue;
        if (dis[u] > dis[o] + cost[i]) {
          dis[u] = dis[o] + cost[i], pre[u] = i;
          if (!inq[u]) inq[u] = true, q.push(u);
        }
      }
    }
    if (dis[T] == oo) return false;
    for (int i = pre[T]; i; i = pre[to[i ^ 1]]) flow[i]--, flow[i ^ 1]++;
    ++sumf, sumc += dis[T];
    return true;
  }
} F;
int n;
struct Tree {
  int Begin[N], Next[N], to[N], e;
  void add(int u, int v) { to[++e] = v, Next[e] = Begin[u], Begin[u] = e; }
  int rt;
  void init() {
    for (int i = 2; i <= n; i++) {
      int u, v;
      scanf("%d%d", &u, &v);
      add(u, v), add(v, u);
    }
  }
  int lim[N];
  int DFS(int o, int fa, bool s) {
    int sum = 0;
    for (int i = Begin[o]; i; i = Next[i]) {
      int u = to[i];
      if (u == fa) continue;
      sum += DFS(u, o, s);
    }
    if (lim[o] != -1) {
      if (lim[o] < sum) {
        puts("-1");
        exit(0);
      }
      if (s)
        F.add(S, o, lim[o] - sum, 0);
      else
        F.add(o + n, T, lim[o] - sum, 0);
      return lim[o];
    } else {
      if (s)
        F.add(fa, o, n, 0);
      else
        F.add(o + n, fa + n, n, 0);
      return sum;
    }
  }
  void getq(bool s) {
    int q;
    scanf("%d", &q);
    memset(lim, -1, sizeof lim);
    while (q--) {
      int x, y;
      scanf("%d%d", &x, &y);
      lim[x] = y;
    }
    DFS(rt, 0, s);
  }
} P[2];
int w[N];
int main() {
  scanf("%d%d%d", &n, &P[0].rt, &P[1].rt);
  S = 2 * n + 1, T = S + 1;
  for (int i = 1; i <= n; i++) scanf("%d", &w[i]);
  for (int i = 0; i <= 1; i++) P[i].init();
  for (int i = 0; i <= 1; i++) P[i].getq(i);
  if (P[0].lim[P[0].rt] != P[1].lim[P[1].rt]) {
    puts("-1");
    return 0;
  }
  for (int i = 1; i <= n; i++) F.add(i, i + n, 1, -w[i]);
  int sumf = 0, sumc = 0;
  while (F.SPFA(sumf, sumc))
    ;
  if (P[0].lim[P[0].rt] > sumf) {
    puts("-1");
    return 0;
  }
  printf("%d\n", -sumc);
  return 0;
}
