class UnionFind:
    def __init__(self, n):
        self.par = [-1]*n
        self.rank = [0]*n

    def Find(self, x):
        if self.par[x] < 0:
            return x
        else:
            self.par[x] = self.Find(self.par[x])
            return self.par[x]

    def Unite(self, x, y):
        x = self.Find(x)
        y = self.Find(y)

        if x != y:
            if self.rank[x] < self.rank[y]:
                self.par[y] += self.par[x]
                self.par[x] = y
            else:
                self.par[x] += self.par[y]
                self.par[y] = x
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def Same(self, x, y):
        return self.Find(x) == self.Find(y)

    def Size(self, x):
        return -self.par[self.Find(x)]

import sys
import io, os
input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline

from collections import defaultdict

n, d, w = map(int, input().split())
uf1 = UnionFind(n)
for i in range(d):
    a, b = map(int, input().split())
    a, b = a-1, b-1
    uf1.Unite(a, b)
uf2 = UnionFind(n)
for i in range(w):
    c, d = map(int, input().split())
    c, d = c-1, d-1
    uf2.Unite(c, d)

X = []
for i in range(n):
    if uf1.par[i] < 0:
        X.append(i)
CX = defaultdict(lambda: 0)
usedY = defaultdict(lambda: set())
for i in range(n):
    x = uf1.Find(i)
    y = uf2.Find(i)
    if y in usedY[x]:
        continue
    CX[x] += uf2.Size(y)
    usedY[x].add(y)

ans = 0
for x in X:
    ans += uf1.Size(x)*(CX[x]-1)
print(ans)