from collections import defaultdict import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) class UF_tree: def __init__(self, n): self.root = [-1] * (n + 1) def find(self, x): stack = [] while self.root[x] >= 0: stack.append(x) x = self.root[x] for i in stack: self.root[i] = x return x def same(self, x, y): return self.find(x) == self.find(y) def unite(self, x, y): x = self.find(x) y = self.find(y) if x == y: return False if -self.root[x] > -self.root[y]: x, y = y, x self.root[y] += self.root[x] self.root[x] = y return True def size(self, x): return -self.root[self.find(x)] N, D, W = map(int, input().split()) car = UF_tree(N) walk = UF_tree(N) for _ in range(D): a, b = map(int, input().split()) car.unite(a-1, b-1) for _ in range(W): a, b = map(int, input().split()) walk.unite(a-1, b-1) ans = 0 group = defaultdict(list) for i in range(N): group[car.find(i)].append(i) ans = 0 for k in group.keys(): used = set() sz = 0 for i in group[k]: x = walk.find(i) if x in used: continue sz += walk.size(x) used.add(x) ans += len(group[k]) * sz print(ans - N)