class UnionFind: def __init__(self, n): self.node = [-1 for _ in range(n)] def root(self, v): if self.node[v] < 0: return v st = [] while self.node[v] >= 0: st.append(v) v = self.node[v] for u in st: self.node[u] = v return v def size(self, v): v = self.root(v) return (- self.node[v]) def same(self, u, v): return self.root(u) == self.root(v) def unite(self, u, v): ru = self.root(u) rv = self.root(v) if ru == rv: return du = self.node[ru] dv = self.node[rv] if du <= dv: self.node[rv] = ru self.node[ru] += dv else: self.node[ru] = rv self.node[rv] += du n, d, w = map(int, input().split()) ufc = UnionFind(n) for _ in range(d): u, v = map(int, input().split()) ufc.unite(u - 1, v - 1) ufw = UnionFind(n) for _ in range(w): u, v = map(int, input().split()) ufw.unite(u - 1, v - 1) g = [set() for _ in range(n)] for v in range(n): rc = ufc.root(v) rw = ufw.root(v) g[rc].add(rw) ans = 0 for u in range(n): if len(g[u]) == 0: continue ans += ufc.size(u) * sum(ufw.size(v) for v in g[u]) ans -= n print(ans)