import sys input = sys.stdin.readline N,D,W=map(int,input().split()) # UnionFind Group0 = [i for i in range(N+1)] # グループ分け Nodes0 = [1]*(N+1) # 各グループのノードの数 def find(x): while Group0[x] != x: x=Group0[x] return x def Union(x,y): if find(x) != find(y): if Nodes0[find(x)] < Nodes0[find(y)]: Nodes0[find(y)] += Nodes0[find(x)] Nodes0[find(x)] = 0 Group0[find(x)] = find(y) else: Nodes0[find(x)] += Nodes0[find(y)] Nodes0[find(y)] = 0 Group0[find(y)] = find(x) # UnionFind Group1 = [i for i in range(N+1)] # グループ分け Nodes1 = [1]*(N+1) # 各グループのノードの数 def find1(x): while Group1[x] != x: x=Group1[x] return x def Union1(x,y): if find1(x) != find1(y): if Nodes1[find1(x)] < Nodes1[find1(y)]: Nodes1[find1(y)] += Nodes1[find1(x)] Nodes1[find1(x)] = 0 Group1[find1(x)] = find1(y) else: Nodes1[find1(x)] += Nodes1[find1(y)] Nodes1[find1(y)] = 0 Group1[find1(y)] = find1(x) for i in range (D): x,y=map(int,input().split()) Union(x,y) for i in range(W): x,y=map(int,input().split()) Union1(x,y) G1_to_G0=[set() for i in range(N+1)] for i in range(N+1): G1_to_G0[find1(i)].add(find(i)) NGroup=[0]*(N+1) for i in range(N+1): if find1(i)==i: for g0 in G1_to_G0[i]: NGroup[g0]+=Nodes1[i] ANS=0 for i in range(1,N+1): if Nodes0[i]==0: continue ANS+=Nodes0[i]*(NGroup[i]-1) print(ANS)