#include using namespace std; typedef long long ll; class UnionFind { public: vector par; vector siz; UnionFind(int sz_): par(sz_), siz(sz_, 1) { for (int i = 0; i < sz_; ++i) par[i] = i; } void init(int sz_) { par.resize(sz_); siz.assign(sz_, 1); for (int i = 0; i < sz_; ++i) par[i] = i; } int root(int x) { while (par[x] != x) { x = par[x] = par[par[x]]; } return x; } bool merge(int x, int y) { x = root(x); y = root(y); if (x == y) return false; if (siz[x] < siz[y]) swap(x, y); siz[x] += siz[y]; par[y] = x; return true; } bool issame(int x, int y) { return root(x) == root(y); } int size(int x) { return siz[root(x)]; } }; int main() { int N,D,W; cin >> N >> D >> W; UnionFind uf_d(N); UnionFind uf_w(N); for(int i = 0;i < D;i++){ int a,b; cin >> a >> b; a--,b--; uf_d.merge(a,b); } for(int i = 0;i < W;i++){ int c,d; cin >> c >> d; c--,d--; uf_w.merge(c,d); } ll ans = 0; map,bool> used; for(int i = 0;i < N;i++){ if(!used[make_pair(uf_d.root(i),uf_w.root(i))]){ ans += (ll)uf_d.size(i) * uf_w.size(i); } used[make_pair(uf_d.root(i),uf_w.root(i))] = true; } cout << ans - N << endl; }