#include <bits/stdc++.h>
using namespace std;

struct Unionfind {
  // tree number
  vector<int> par;
  // constructor
  Unionfind(int n = 1) : par(n, -1) {}
  // search root
  int root(int x) {
    if (par[x] < 0) return x;
    return par[x] = root(par[x]);
  }
  // is same?
  bool issame(int x, int y) { return root(x) == root(y); }

  // add
  // already added, return 0
  bool uni(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return 0;
    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;
    return 1;
  }
  int size(int x) { return -par[root(x)]; }
};

using P = pair<int, int>;

long long n, d, w;
Unionfind ufd, ufw;
vector<long long> cnt;

int main() {
  cin >> n >> d >> w;
  ufd = ufw = Unionfind(n);
  for (int i = 0; i < d; ++i) {
    int x, y;
    cin >> x >> y;
    ufd.uni(--x, --y);
  }
  for (int i = 0; i < w; ++i) {
    int x, y;
    cin >> x >> y;
    ufw.uni(--x, --y);
  }
  cnt.assign(n, 0);
  set<P> st;
  for (int i = 0; i < n; ++i) {
    int f = ufd.root(i), t = ufw.root(i);
    if (!st.count(P(f, t))) cnt[f] += ufw.size(t);
    st.insert(P(f, t));
  }
  long long res = -n;
  for (int i = 0; i < n; ++i) res += cnt[ufd.root(i)];
  cout << res << endl;
  return 0;
}