import std.conv, std.functional, std.range, std.stdio, std.string; import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons; import core.bitop; class EOFException : Throwable { this() { super("EOF"); } } string[] tokens; string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; } int readInt() { return readToken.to!int; } long readLong() { return readToken.to!long; } real readReal() { return readToken.to!real; } bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } } bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } } int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; } int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); } int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); } int root(int[] uf, int u) { return (uf[u] < 0) ? u : (uf[u] = uf.root(uf[u])); } bool connect(int[] uf, int u, int v) { u = uf.root(u); v = uf.root(v); if (u == v) return false; if (uf[u] > uf[v]) swap(u, v); uf[u] += uf[v]; uf[v] = u; return true; } enum E = 18; int N, M, Q; int[] U, V; int[] A, B; int[][] G; long[] freq, freqSum; int[][] par; int[] dep; void dfs(int u, int p) { par[0][u] = p; dep[u] = (p == -1) ? 0 : (dep[p] + 1); freqSum[u] = freq[u]; foreach (v; G[u]) { if (v != p) { dfs(v, u); freqSum[u] += freqSum[v]; } } } int lca(int u, int v) { foreach_reverse (e; 0 .. E) { if (dep[u] - (1 << e) >= dep[v]) { u = par[e][u]; } if (dep[v] - (1 << e) >= dep[u]) { v = par[e][v]; } } foreach_reverse (e; 0 .. E) { if (par[e][u] != par[e][v]) { u = par[e][u]; v = par[e][v]; } } if (u != v) { u = par[0][u]; v = par[0][v]; } return u; } void main() { try { for (; ; ) { N = readInt(); M = readInt(); Q = readInt(); U = new int[M]; V = new int[M]; foreach (i; 0 .. M) { U[i] = readInt() - 1; V[i] = readInt() - 1; } A = new int[Q]; B = new int[Q]; foreach (q; 0 .. Q) { A[q] = readInt() - 1; B[q] = readInt() - 1; } G = new int[][N]; foreach (i; 0 .. M) { G[U[i]] ~= V[i]; G[V[i]] ~= U[i]; } auto uf = new int[N]; uf[] = -1; foreach (i; 0 .. M) { uf.connect(U[i], V[i]); } freq = new long[N]; foreach (q; 0 .. Q) { if (uf.root(A[q]) != uf.root(B[q])) { ++freq[A[q]]; ++freq[B[q]]; } } freqSum = new long[N]; dep = new int[N]; par = new int[][](E, N); foreach (u; 0 .. N) { if (uf[u] < 0) { debug { writeln("root ", u); } dfs(u, u); } } foreach (e; 0 .. E - 1) { foreach (u; 0 .. N) { par[e + 1][u] = par[e][par[e][u]]; } } debug { writeln("freqSum = ", freqSum); } long ans; foreach (q; 0 .. Q) { if (uf.root(A[q]) == uf.root(B[q])) { const l = lca(A[q], B[q]); const cost = dep[A[q]] + dep[B[q]] - 2 * dep[l]; debug { writeln("same ", A[q], " ", B[q], ": ", cost); } ans += cost; } } foreach (u; 0 .. N) { if (par[0][u] != u) { ans += min(freqSum[u], freqSum[uf.root(u)] - freqSum[u]); } } writeln(ans); } } catch (EOFException e) { } }