class UnionFind: def __init__(self, size): self.data = [-1] * size def root(self, x): if self.data[x] < 0: return x ans = self.root(self.data[x]) self.data[x] = ans return ans def unite(self, x, y): x = self.root(x) y = self.root(y) if x == y: return False if self.data[x] > self.data[y]: x, y = y, x self.data[x] += self.data[y] self.data[y] = x return True def size(self, x): return -self.data[self.root(x)] n, d, w = map(int, input().split()) assert(2 <= n <= 100000) assert(1 <= d <= min(100000, n * (n + 1) // 2)) assert(1 <= w <= min(100000, n * (n + 1) // 2)) a = [] for i in range(d): x, y = map(int, input().split()) assert(1 <= x < y <= n) a.append((x - 1, y - 1)) assert(len(set(a)) == d) b = [] for i in range(w): x, y = map(int, input().split()) assert(1 <= x < y <= n) b.append((x - 1, y - 1)) assert(len(set(b)) == w) car = UnionFind(n) walk = UnionFind(n) for x, y in a: car.unite(x, y) for x, y in b: walk.unite(x, y) cnt = [0] * n s = [set() for i in range(n)] for i in range(n): x = car.root(i) y = walk.root(i) if y not in s[x]: s[x].add(y) cnt[x] += walk.size(y) ans = 0 for i in range(n): ans += cnt[car.root(i)] - 1 print(ans)