#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...)); } class lowest_common_ancestor { std::vector> g, parent; std::vector depth; const size_t logN = 20; private: void dfs(size_t v, int par = -1, size_t d = 0) { parent[0][v] = par; depth[v] = d; for(auto e:g[v]) { if(e == par) continue; dfs(e, v, d + 1); } } void build() { for(int i = 0; i < g.size(); i++) if(depth[i] == -1) dfs(i); for(int k = 0; k < logN - 1; k++) { for(int i = 0; i < g.size(); i++) { if(parent[k][i] == -1) parent[k + 1][i] = -1; else parent[k + 1][i] = parent[k][parent[k][i]]; } } } public: lowest_common_ancestor() {} lowest_common_ancestor(int n) : g(n), depth(n, -1) { parent.assign(logN, std::vector(n, -1)); } void add_edge(const size_t & u, const size_t & v) { g[u].push_back(v); g[v].push_back(u); } const size_t query(size_t u, size_t v) { static bool built = false; if(!built) { build(); built = true; } if(depth[u] > depth[v]) std::swap(u, v); for(int k = 0; k < logN; k++) { if(((depth[v] - depth[u]) >> k) & 1) v = parent[k][v]; } if(u == v) return u; for(int k = logN - 1; k >= 0; k--) { if(parent[k][u] == parent[k][v]) continue; u = parent[k][u]; v = parent[k][v]; } return parent[0][u]; } }; int main() { int n, m, q; scanf("%d%d%d", &n, &m, &q); lowest_common_ancestor lca(n); 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); lca.add_edge(a - 1, b - 1); } int cnt = 0; std::vector comp(n, -1), dist(n); 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; dist[e] = dist[v] + 1; kiri(kiri, e, v); } }; kiri(kiri, i, -1); cnt++; } auto calc = [dist, &lca](int a, int b) -> i64 { return dist[a] + dist[b] - 2 * dist[lca.query(a, b)]; }; 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>> dp(n); auto dfs = [&](auto && dfs, int v, int par, bool f) -> std::pair { if(dp[v].count(par)) return dp[v][par]; cout << v << " " << par << endl; std::pair val{0, p[v]}; if(par == -1 or f) { for(auto e: g[v]) { if(e == par) continue; auto p = dfs(dfs, e, v, f); val.first += p.first + p.second; val.second += p.second; } } else { auto p = dfs(dfs, par, v, 0); auto q = dfs(dfs, v, -1, 0); val.first = q.first - (p.first + p.second); val.second = q.second - p.second; } return dp[v][par] = val; }; std::vector used(cnt, false); for(int i = 0; i < n; i++) { if(used[comp[i]]) continue; used[comp[i]] = true; dfs(dfs, i, -1, true); } std::vector latte(cnt, 1LL << 60); for(int i = 0; i < n; i++) latte[comp[i]] = std::min(latte[comp[i]], dfs(dfs, i, -1, 0).first); for(auto v: latte) ans += v; printf("%lld\n", ans); return 0; }