import java.util.*; public class Main { public static void main (String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int d = sc.nextInt(); int w = sc.nextInt(); UnionFindTree dUft = new UnionFindTree(n); UnionFindTree wUft = new UnionFindTree(n); for (int i = 0; i < d; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; dUft.unite(a, b); } for (int i = 0; i < w; i++) { int a = sc.nextInt() - 1; int b = sc.nextInt() - 1; wUft.unite(a, b); } HashMap dCount = new HashMap<>(); HashMap wCount = new HashMap<>(); HashMap> bridge = new HashMap<>(); for (int i = 0; i < n; i++) { int x = dUft.find(i); if (!dCount.containsKey(x)) { dCount.put(x, dUft.counts[x]); } int y = wUft.find(i); if (!wCount.containsKey(y)) { wCount.put(y, wUft.counts[y]); } if (!bridge.containsKey(x)) { bridge.put(x, new HashSet<>()); } bridge.get(x).add(y); } long ans = 0; for (Map.Entry> entry : bridge.entrySet()) { long count = 0; for (int y : entry.getValue()) { count += wCount.get(y); } ans += (count - 1) * dCount.get(entry.getKey()); } System.out.println(ans); } static class UnionFindTree { int[] parents; int[] counts; public UnionFindTree(int size) { parents = new int[size]; counts = new int[size]; for (int i = 0; i < size; i++) { parents[i] = i; counts[i] = 1; } } 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) { int xx = find(x); int yy = find(y); if (xx == yy) { return; } parents[xx] = yy; counts[yy] += counts[xx]; } } }