#include using namespace std; using lint = long long; struct fast_ios { fast_ios(){ cin.tie(nullptr), ios::sync_with_stdio(false), cout << fixed << setprecision(20); }; } fast_ios_; #define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i par, cou; UnionFind(int N = 0) : par(N), cou(N, 1) { iota(par.begin(), par.end(), 0); } int find(int x) { return (par[x] == x) ? x : (par[x] = find(par[x])); } bool unite(int x, int y) { x = find(x), y = find(y); if (x == y) return false; if (cou[x] < cou[y]) std::swap(x, y); par[y] = x, cou[x] += cou[y]; return true; } int count(int x) { return cou[find(x)]; } bool same(int x, int y) { return find(x) == find(y); } }; int main() { int N, D, W; cin >> N >> D >> W; UnionFind uf1(N); while (D--) { int a, b; cin >> a >> b; a--, b--; uf1.unite(a, b); } UnionFind uf2(N); while (W--) { int a, b; cin >> a >> b; a--, b--; uf2.unite(a, b); } map> mp; vector sz(N); REP(i, N) mp[uf2.find(i)].insert(uf1.find(i)), sz[uf2.find(i)]++; lint ret = 0; REP(r, N) if (sz[r]) { lint s = 0; for (auto x : mp[r]) s += uf1.count(x); ret += s * sz[r] - sz[r]; } cout << ret << '\n'; }