#include using namespace std; template bool cmin(T &a, U b) { return a > b && (a = b, true); } template bool cmax(T &a, U b) { return a < b && (a = b, true); } class UnionFind { private: int N; vector PS; public: UnionFind() : N(0) {} UnionFind(int n) : N(n), PS(n, -1) {} bool unite(int a, int b) { int x = root(a), y = root(b); if (x == y) return false; if (-PS.at(x) < -PS.at(y)) swap(x, y); PS.at(x) += PS.at(y); PS.at(y) = x; return true; } bool same(int a, int b) { return root(a) == root(b); } int root(int a) { if (PS.at(a) < 0) return a; return PS.at(a) = root(PS.at(a)); } int size(int a) { return -PS.at(root(a)); } vector> groups() { vector B(N), S(N); for (int i = 0; i < N; i++) { B.at(i) = root(i); S.at(B.at(i))++; } vector> ret(N); for (int i = 0; i < N; i++) { ret.at(i).reserve(S.at(i)); } for (int i = 0; i < N; i++) { ret.at(B.at(i)).push_back(i); } auto f = [&](const vector &v) { return v.empty(); }; ret.erase(remove_if(ret.begin(), ret.end(), f), ret.end()); return ret; } }; signed main() { cin.tie(nullptr); ios_base::sync_with_stdio(false); int N, D, W; cin >> N >> D >> W; UnionFind UF(N); UnionFind UF2(N); for (int i = 0; i < D; i++) { int a, b; cin >> a >> b, a--, b--; UF.unite(a, b); } for (int i = 0; i < W; i++) { int a, b; cin >> a >> b, a--, b--; UF2.unite(a, b); } long ans = 0; set> tmp; for (int i = 0; i < N; i++) { if (tmp.count({UF.root(i), UF2.root(i)})) continue; tmp.insert({UF.root(i), UF2.root(i)}); ans += (long)UF.size(UF.root(i)) * UF2.size(UF2.root(i)); } cout << ans - N << "\n"; }