#include using namespace std; using lint = long long; template using V = vector; template using VV = V< V >; struct UnionFind { V<> t; UnionFind(int n) : t(n, -1) {} int find(int v) { return t[v] < 0 ? v : t[v] = find(t[v]); } void unite(int u, int v) { u = find(u); v = find(v); if (u == v) return; if (-t[u] < -t[v]) swap(u, v); t[u] += t[v]; t[v] = u; } int size(int v) { return -t[find(v)]; } }; template struct SparseTable { VV t; SparseTable(const V& a) : t(1, a) { for (int k = 1, n = a.size(); 1 << k <= n; ++k) { t.emplace_back(n - (1 << k) + 1); for (int i = 0; i + (1 << k) <= n; ++i) { t[k][i] = min(t[k - 1][i], t[k - 1][i + (1 << (k - 1))]); } } } T acc(int l, int r) const { assert(l < r); int k = __lg(r - l); return min(t[k][l], t[k][r - (1 << k)]); } }; int main() { cin.tie(nullptr); ios::sync_with_stdio(false); int n, m, q; cin >> n >> m >> q; UnionFind uf(n); VV<> g(n); while (m--) { int u, v; cin >> u >> v, --u, --v; uf.unite(u, v); g[u].push_back(v); g[v].push_back(u); } V<> dep(n), vs; { V vis(n); auto dfs = [&](auto& F, int v, int p) -> void { vis[v] = true; vs.push_back(v); for (int u : g[v]) if (u != p) { dep[u] = dep[v] + 1; F(F, u, v); vs.push_back(v); } }; for (int v = 0; v < n; ++v) if (not vis[v]) { dfs(dfs, v, -1); } } V< pair > _st; V<> id(n, 1e9); for (int i = 0; i < (int)vs.size(); ++i) { _st.emplace_back(dep[vs[i]], vs[i]); id[vs[i]] = min(id[vs[i]], i); } SparseTable< pair > st(_st); V<> cum(vs.size() + 1); for (int i = (int)vs.size() - 2; i >= 0; --i) { int d = dep[vs[i]] < dep[vs[i + 1]] ? 1 : -1; cum[i] = d + cum[i + 1]; } auto lca = [&](int u, int v) -> int { if (u == v) return u; tie(u, v) = minmax(id[u], id[v]); return st.acc(u, v).second; }; auto len = [&](int u, int v) -> int { int a = lca(u, v); return 2 * cum[id[a]] - cum[id[u]] - cum[id[v]]; }; lint res = 0; V<> cnt(n); while (q--) { int u, v; cin >> u >> v, --u, --v; if (uf.find(u) == uf.find(v)) { res += len(u, v); } else { ++cnt[u]; ++cnt[v]; } } V<> sz(n); { V vis(n); auto dfs = [&](auto& F, int v, int p) -> void { vis[v] = true; sz[v] = cnt[v]; for (int u : g[v]) if (u != p) { F(F, u, v); sz[v] += sz[u]; } }; for (int v = 0; v < n; ++v) if (not vis[v]) { dfs(dfs, v, -1); } } V<> cent(n, -1); { V vis(n); int csz = -1; auto dfs = [&](auto& F, int v, int p) -> void { vis[v] = true; bool ok = 2 * (csz - sz[v]) <= csz; for (int u : g[v]) if (u != p) { F(F, u, v); if (2 * sz[u] > csz) ok = false; } if (ok) { cent[uf.find(v)] = v; } }; for (int v = 0; v < n; ++v) if (not vis[v]) { csz = sz[v]; dfs(dfs, v, -1); } } for (int v = 0; v < n; ++v) { res += (lint)cnt[v] * len(v, cent[uf.find(v)]); } cout << res << '\n'; }