class UnionFind(): def __init__(self, n): self.n = n self.parents = [-1] * n def find(self, x): if self.parents[x] < 0: return x else: self.parents[x] = self.find(self.parents[x]) return self.parents[x] def union(self, x, y): x = self.find(x) y = self.find(y) if x == y: return if self.parents[x] > self.parents[y]: x, y = y, x self.parents[x] += self.parents[y] self.parents[y] = x def same(self, x, y): return self.find(x) == self.find(y) def roots(self): return [i for i, x in enumerate(self.parents) if x < 0] def members(self, x): root = self.find(x) return [i for i in range(self.n) if self.find(i) == root] def size(self, x): return abs(self.parents[self.find(x)]) def groups(self): roots = self.roots() r_to_g = {} for i, r in enumerate(roots): r_to_g[r] = i groups = [[] for _ in roots] for i in range(self.n): groups[r_to_g[self.find(i)]].append(i) return groups n, d, w = map(int, input().split()) uf1 = UnionFind(n) uf2 = UnionFind(n) for _ in range(d): p, q = map(int, input().split()) p -= 1 q -= 1 uf1.union(p, q) for _ in range(w): p, q = map(int, input().split()) p -= 1 q -= 1 uf2.union(p, q) res = 0 # print(uf1.groups()) # print(uf2.groups()) for g in uf2.groups(): goal = uf2.size(g[0]) start = 0 used = {} for v in g: r = uf1.find(v) if r not in used: start += uf1.size(r) used[r] = 1 res += (start-1)*goal print(res)