#include <bits/stdc++.h>
using namespace std;
struct Edge {
  int from, to, capacity, cost;
  Edge(int f, int t, int c, int co) : from(f), to(t), capacity(c), cost(co) {}
};
vector<vector<int>> adj, cost, capacity;
const int INF = 1e9;
void shortest_paths(int n, int v0, vector<int>& d, vector<int>& p) {
  d.assign(n, INF);
  d[v0] = 0;
  vector<int> m(n, 2);
  deque<int> q;
  q.push_back(v0);
  p.assign(n, -1);
  while (!q.empty()) {
    int u = q.front();
    q.pop_front();
    m[u] = 0;
    for (int v : adj[u]) {
      if (capacity[u][v] > 0 && d[v] > d[u] + cost[u][v]) {
        d[v] = d[u] + cost[u][v];
        p[v] = u;
        if (m[v] == 2) {
          m[v] = 1;
          q.push_back(v);
        } else if (m[v] == 0) {
          m[v] = 1;
          q.push_front(v);
        }
      }
    }
  }
}
int min_cost_flow(int N, vector<Edge> edges, int K, int s, int t) {
  adj.assign(N, vector<int>());
  cost.assign(N, vector<int>(N, 0));
  capacity.assign(N, vector<int>(N, 0));
  for (Edge e : edges) {
    adj[e.from].push_back(e.to);
    adj[e.to].push_back(e.from);
    cost[e.from][e.to] = e.cost;
    cost[e.to][e.from] = -e.cost;
    capacity[e.from][e.to] = e.capacity;
  }
  int flow = 0;
  int cost = 0;
  vector<int> d, p;
  while (flow < K) {
    shortest_paths(N, s, d, p);
    if (d[t] == INF) break;
    int f = K - flow;
    int cur = t;
    while (cur != s) {
      f = min(f, capacity[p[cur]][cur]);
      cur = p[cur];
    }
    flow += f;
    cost += f * d[t];
    cur = t;
    while (cur != s) {
      capacity[p[cur]][cur] -= f;
      capacity[cur][p[cur]] += f;
      cur = p[cur];
    }
  }
  if (flow < K)
    return -1;
  else
    return -cost;
}
int n;
vector<Edge> edges;
int dfs(vector<vector<int>> const& adj, vector<int> const& demands, int v,
        int p, bool forward) {
  int cur = demands[v];
  int children = 0;
  for (int u : adj[v]) {
    if (u == p) continue;
    if (demands[u] == 0) {
      if (forward)
        edges.emplace_back(v, u, INF, 0);
      else
        edges.emplace_back(u + n, v + n, INF, 0);
    }
    children += dfs(adj, demands, u, v, forward);
  }
  if (cur > 0) {
    if (cur >= children) {
      if (cur > children) {
        if (forward)
          edges.emplace_back(2 * n, v, cur - children, 0);
        else
          edges.emplace_back(n + v, 2 * n + 1, cur - children, 0);
      }
    } else {
      cout << -1 << '\n';
      exit(0);
    }
    return cur;
  }
  return children;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<int> a(n);
  for (auto& x : a) cin >> x;
  vector<vector<int>> adj;
  adj.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  vector<vector<int>> adj2;
  adj2.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int u, v;
    cin >> u >> v;
    u--, v--;
    adj2[u].push_back(v);
    adj2[v].push_back(u);
  }
  vector<int> demands1(n, 0);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int j, c;
    cin >> j >> c;
    demands1[j - 1] = c;
  }
  vector<int> demands2(n, 0);
  cin >> q;
  for (int i = 0; i < q; i++) {
    int j, c;
    cin >> j >> c;
    demands2[j - 1] = c;
  }
  for (int i = 0; i < n; i++) {
    edges.emplace_back(i, i + n, 1, -a[i]);
  }
  int sum1 = dfs(adj, demands1, x, -1, true);
  int sum2 = dfs(adj2, demands2, y, -1, false);
  if (sum1 != sum2) {
    cout << -1 << '\n';
    exit(0);
  }
  int ret = min_cost_flow(2 * n + 2, edges, sum1, 2 * n, 2 * n + 1);
  cout << ret << '\n';
}
