import java.io.*; import java.util.*; public class Main { public static void main(String[] args) throws Exception { Scanner sc = new Scanner(); int n = sc.nextInt(); int d = sc.nextInt(); int w = sc.nextInt(); UnionFindTree drive = new UnionFindTree(n); UnionFindTree walk = new UnionFindTree(n); for (int i = 0; i < d; i++) { drive.unite(sc.nextInt() - 1, sc.nextInt() - 1); } for (int i = 0; i < w; i++) { walk.unite(sc.nextInt() - 1, sc.nextInt() - 1); } HashMap> dUnion = new HashMap<>(); HashMap> cUnion = new HashMap<>(); HashMap> wUnion = new HashMap<>(); for (int i = 0; i < n; i++) { int pd = drive.find(i); if (!dUnion.containsKey(pd)) { dUnion.put(pd, new HashSet<>()); cUnion.put(pd, new HashSet<>()); } dUnion.get(pd).add(i); int pw = walk.find(i); if (!wUnion.containsKey(pw)) { wUnion.put(pw, new HashSet<>()); } cUnion.get(pd).add(pw); wUnion.get(pw).add(i); } long ans = 0; for (int x : dUnion.keySet()) { long count = 0; for (int y : cUnion.get(x)) { for (int z : wUnion.get(y)) { if (!dUnion.get(x).contains(z)) { count++; } } } long size = dUnion.get(x).size(); ans += (size - 1 + count) * size; } System.out.println(ans); } static class UnionFindTree { int[] parents; public UnionFindTree(int size) { parents = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; } } public int find(int x) { if (x == parents[x]) { return x; } else { return parents[x] = find(parents[x]); } } public boolean same(int x, int y) { return find(x) == find(y); } public void unite(int x, int y) { if (!same(x, y)) { parents[find(x)] = find(y); } } } } class Scanner { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); StringBuilder sb = new StringBuilder(); public Scanner() throws Exception { } public int nextInt() throws Exception { return Integer.parseInt(next()); } public long nextLong() throws Exception { return Long.parseLong(next()); } public double nextDouble() throws Exception { return Double.parseDouble(next()); } public String next() throws Exception { while (!st.hasMoreTokens()) { st = new StringTokenizer(br.readLine()); } return st.nextToken(); } }