#include using namespace std; using lint = long long; const lint mod = 1e9 + 7; #define all(x) (x).begin(), (x).end() #define bitcount(n) __builtin_popcountl((lint)(n)) #define fcout cout << fixed << setprecision(15) #define highest(x) (63 - __builtin_clzl(x)) template inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; } template inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; } templateint character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; } lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }} struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); } template string to_string(pair x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; } template void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; } template void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } } template T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template T lcm(T a, T b){ return a / gcd(a, b) * b; } struct combination{ vector fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } }; template bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; } template bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; } class LCA{ vector> roads; bool is_built; int size; vector depth; vector parent; vector> ancestor; vector is_came; vector group_number; void make_rooted(int vertex, int back, int depth_now, int group_now){ depth[vertex] = depth_now; is_came[vertex] = true; group_number[vertex] = group_now; for(int i: roads[vertex]){ if(i != back){ parent[i] = vertex; make_rooted(i, vertex, depth_now + 1, group_now); } } } public: int find_ancestor(int vertex, int height, int bit = 31){ if(vertex == -1){ return -1; }else if(bit == -1){ return vertex; }else if((height >> bit) & 1){ return find_ancestor(ancestor[bit][vertex], height, bit - 1); }else{ return find_ancestor(vertex, height, bit - 1); } } LCA(int n): size(n), roads(n), is_built(false) {} void connect(int a, int b){ is_built = false; roads[a].push_back(b); roads[b].push_back(a); } void build(){ is_built = true; parent = vector(size); depth = vector(size); group_number = vector(size); is_came = vector(size, false); int group_count = 0; for(int i = 0; i < size; i++){ if(!is_came[i]){ parent[i] = -1; make_rooted(i, -1, 0, group_count); group_count++; } } ancestor.resize(32, vector(size)); for(int i = 0; i < size; i++){ ancestor[0][i] = parent[i]; } for(int i = 1; i < 32; i++){ for(int j = 0; j < size; j++){ if(ancestor[i - 1][j] == -1){ ancestor[i][j] = -1; }else{ ancestor[i][j] = ancestor[i - 1][ancestor[i - 1][j]]; } } } } bool is_same_group(int a, int b){ return group_number[a] == group_number[b]; } int dist(int a, int b){ if(!is_built){ cout << "ERROR : Not built!" << endl; exit(1); } if(group_number[a] != group_number[b]){ return -1; } int above = min(depth[a], depth[b]); int low = -1, high = above; while(low + 1 < high){ int mid = (low + high) / 2; if(find_ancestor(a, depth[a] - above + mid) == find_ancestor(b, depth[b] - above + mid)){ high = mid; }else{ low = mid; } } return high * 2 + max(depth[a], depth[b]) - above; } }; int N; vector> roads; vector cnt; lint sum; vector is_came; lint get_ans(int now, int back, int dist){ lint ans = dist * cnt[now]; for(int i: roads[now]){ if(i == back){ continue; } ans += get_ans(i, now, dist + 1); } return ans; } vector size; lint get_size(int now, int back){ lint ans = cnt[now]; for(int i: roads[now]){ if(i == back){ continue; } ans += get_size(i, now); } return size[now] = ans; } lint dfs(int now, int back, lint here_ans){ is_came[now] = true; lint ans = here_ans; for(int i: roads[now]){ if(i == back){ continue; } ans = min(ans, dfs(i, now, here_ans + sum - size[i] * 2)); } return ans; } int main(){ int M, Q; cin >> N >> M >> Q; roads.resize(N); LCA graph(N); for(int i = 0; i < M; i++){ int a, b; cin >> a >> b; a--, b--; roads[a].push_back(b); roads[b].push_back(a); graph.connect(a, b); } cnt.resize(N, 0); lint ans = 0; graph.build(); for(int i = 0; i < Q; i++){ int a, b; cin >> a >> b; a--, b--; if(graph.is_same_group(a, b)){ ans += graph.dist(a, b); }else{ cnt[a]++, cnt[b]++; } } is_came.resize(N, false); size.resize(N); for(int i = 0; i < N; i++){ if(!is_came[i] && roads[i].size() <= 1){ sum = get_size(i, -1); ans += dfs(i, -1, get_ans(i, -1, 0)); } } cout << ans << endl; }