class UnionFind(): def __init__(self, n): self.n = n self.par = list(range(self.n)) self.rank = [1] * n self.count = n def find(self, x): if self.par[x] == x: return x else: self.par[x] = self.find(self.par[x]) return self.par[x] def unite(self, x, y): p = self.find(x) q = self.find(y) if p == q: return None if p > q: p, q = q, p self.rank[p] += self.rank[q] self.par[q] = p self.count -= 1 def same(self, x, y): return self.find(x) == self.find(y) def size(self, x): return self.rank[x] def count(self): return self.count n, d, w = map(int, input().split()) UF1, UF2 = UnionFind(n), UnionFind(n) for i in range(d): a, b = map(int, input().split()) UF1.unite(a - 1, b - 1) for i in range(w): c, d = map(int, input().split()) UF2.unite(c - 1, d - 1) l = [0] * n s = [set() for i in range(n)] for i in range(n): x, y = UF1.find(i), UF2.find(i) if y not in s[x]: s[x].add(y) l[x] += UF2.size(y) print(sum(l[UF1.find(i)] - 1 for i in range(n)))