#include <bits/stdc++.h>
using namespace std;
const int maxn = 2010;
const int INF = 1e9;
struct Edge {
  int from, to, cap, flow, cost;
  Edge() {}
  Edge(int u, int v, int c, int f, int co)
      : from(u), to(v), cap(c), flow(f), cost(co) {}
};
vector<Edge> edges;
vector<int> G[maxn];
struct MCMF {
  int n, m, s, t;
  int dis[maxn];
  int h[maxn];
  int p[maxn];
  void init(int n) {
    this->n = n;
    for (int i = 0; i < n; i++) G[i].clear();
    edges.clear();
  }
  void AddEdge(int from, int to, int cap, int cost) {
    edges.push_back(Edge(from, to, cap, 0, cost));
    edges.push_back(Edge(to, from, 0, 0, -cost));
    m = (int)edges.size();
    G[from].push_back(m - 2);
    G[to].push_back(m - 1);
  }
  bool dijkstra(int s, int t, int& max_flow, long long& cost) {
    priority_queue<pair<int, int>, vector<pair<int, int> >,
                   greater<pair<int, int> > >
        pq;
    for (int i = 0; i < n; i++) dis[i] = INF;
    dis[s] = 0, pq.push(pair<int, int>(0, s));
    while (!pq.empty()) {
      pair<int, int> u = pq.top();
      pq.pop();
      int v = u.second;
      if (dis[v] < u.first) continue;
      for (int i = 0; i < (int)G[v].size(); i++) {
        Edge& e = edges[G[v][i]];
        if (e.cap > e.flow && dis[e.to] > dis[v] + e.cost + h[v] - h[e.to]) {
          dis[e.to] = dis[v] + e.cost + h[v] - h[e.to];
          p[e.to] = G[v][i];
          pq.push(pair<int, int>(dis[e.to], e.to));
        }
      }
    }
    if (dis[t] == INF) return 0;
    for (int i = 0; i < n; i++) h[i] += dis[i];
    int d = max_flow;
    for (int u = t; u != s; u = edges[p[u]].from)
      d = min(d, edges[p[u]].cap - edges[p[u]].flow);
    max_flow -= d;
    cost += (long long)d * (long long)h[t];
    for (int u = t; u != s; u = edges[p[u]].from) {
      edges[p[u]].flow += d;
      edges[p[u] ^ 1].flow -= d;
    }
    return 1;
  }
  bool MincostMaxflow(int s, int t, int max_flow, long long& cost) {
    this->s = s, this->t = t;
    cost = 0;
    for (int i = 0; i < n; i++) h[i] = 0;
    while (dijkstra(s, t, max_flow, cost) && max_flow)
      ;
    return max_flow == 0;
  }
};
void out() {
  puts("-1");
  exit(0);
}
vector<int> g[2][maxn];
int a[maxn];
int dm[2][maxn], dp[maxn];
int f[2][maxn];
vector<int> tmp;
void dfs(int u, int fa, int id) {
  if (dm[id][u] != -1) tmp.push_back(u);
  f[id][u] = tmp.back();
  for (int v : g[id][u])
    if (v != fa) {
      dfs(v, u, id);
      dp[u] += dp[v];
    }
  if (dm[id][u] != -1) {
    dm[id][u] -= dp[u], dp[u] += dm[id][u];
    if (dm[id][u] < 0) out();
  }
  if (tmp.back() == u) tmp.pop_back();
}
int main() {
  int n, x, y;
  scanf("%d%d%d", &n, &x, &y);
  x--, y--;
  for (int i = 0; i < n; i++) scanf("%d", &a[i]);
  for (int j = 0; j < 2; j++) {
    for (int i = 1; i < n; i++) {
      int a, b;
      scanf("%d%d", &a, &b);
      a--, b--;
      g[j][a].push_back(b), g[j][b].push_back(a);
    }
  }
  memset(dm, -1, sizeof(dm));
  for (int i = 0; i < 2; i++) {
    int q;
    scanf("%d", &q);
    while (q--) {
      int k, x;
      scanf("%d%d", &k, &x);
      k--;
      dm[i][k] = x;
    }
  }
  if (dm[0][x] != dm[1][y]) out();
  int flow = dm[0][x];
  for (int i = 0; i < 2; i++) {
    memset(dp, 0, sizeof(dp));
    dfs((i ? y : x), -1, i);
  }
  MCMF solver;
  solver.init(3 * n + 5);
  int s = 3 * n, t = 3 * n + 1;
  for (int i = 0; i < n; i++) {
    solver.AddEdge(f[0][i], n + i, 1, -a[i]);
    if (f[0][i] == i) solver.AddEdge(s, i, dm[0][i], 0);
  }
  for (int i = 0; i < n; i++) {
    solver.AddEdge(n + i, n + n + f[1][i], 1, 0);
    if (f[1][i] == i) solver.AddEdge(n + n + i, t, dm[1][i], 0);
  }
  long long cost = 0;
  if (!solver.MincostMaxflow(s, t, flow, cost)) out();
  printf("%lld\n", -cost);
  return 0;
}
