#include #include using namespace atcoder; using namespace std; using ll = long long; ll inf = 1e9; int main() { int N, D, W;cin >> N >> D >> W; dsu uf1(N) , uf2(N); for (int i = 0;i < D;i++) { int a, b;cin >> a >> b; a--;b--; uf1.merge(a,b); } for (int i = 0;i < W;i++) { int c, d;cin >> c >> d; c--;d--; uf2.merge(c, d); } map, int> cnt; for (int v = 0;v < N;v++) cnt[{uf1.leader(v), uf2.leader(v)}]++; ll ans = 0; vector> LD(N); for (int v = 0;v < N;v++) { LD[uf1.leader(v)].insert(uf2.leader(v)); } vector SC(N); for (int v = 0;v < N;v++) { if (uf1.leader(v) != v) continue; ll s = 0; for (auto t : LD[v]) { s += uf2.size(t) - cnt[{v, uf2.leader(t)}]; } SC[v] = s; } for (int v = 0;v < N;v++) { ans += (uf1.size(v) - 1) + SC[uf1.leader(v)]; } cout << ans << endl; }