#include using namespace std::literals::string_literals; using i64 = long long; using std::cout; using std::endl; using std::cin; template std::vector make_v(size_t a){return std::vector(a);} template auto make_v(size_t a,Ts... ts){ return std::vector(ts...))>(a,make_v(ts...)); } int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); std::vector> g(n); for(int i = 0; i < m; i++) { int a, b; scanf("%d%d", &a, &b); g[a - 1].push_back(b - 1); g[b - 1].push_back(a - 1); } int cnt = 0; std::vector comp(n, -1); for(int i = 0; i < n; i++) { if(comp[i] != -1) continue; auto kiri = [&](auto && kiri, int v, int par) -> void { comp[v] = cnt; for(auto e: g[v]) { if(e == par) continue; kiri(kiri, e, v); } }; kiri(kiri, i, -1); cnt++; } auto calc = [g](int v, int u) -> i64 { std::queue qu({v}); std::vector min_cost(g.size(), 1 << 30); min_cost[v] = 0; while(!qu.empty()) { auto v = qu.front(); qu.pop(); for(auto e: g[v]) { if(min_cost[e] <= min_cost[v] + 1) continue; min_cost[e] = min_cost[v] + 1; qu.push(e); } } return min_cost[u]; }; i64 ans = 0; std::vector p(n); while(q--) { int a, b; scanf("%d%d", &a, &b); a--; b--; if(comp[a] != comp[b]) { p[a]++; p[b]++; } else { ans += calc(a, b); } } std::vector latte(cnt, 1LL << 60); for(int i = 0; i < n; i++) { i64 tmp = 0; auto dfs = [&](auto dfs, int v, int par, i64 d) -> void { tmp += p[v] * d; for(auto e: g[v]) { if(e == par) continue; dfs(dfs, e, v, d + 1); } }; dfs(dfs, i, -1, 0); latte[comp[i]] = std::min(latte[comp[i]], tmp); } for(auto v: latte) ans += v; printf("%lld\n", ans); return 0; }