#include using namespace std; #define FOR(i, m, n) for(int (i) = (m); (i) < (n); (i)++) #define FORN(i, m, n) for(int (i) = (m); (i) <= (n); (i)++) #define FORR(i, m, n) for(int (i) = (m); (i) >= (n); (i)--) #define rep(i, n) FOR(i, 0, n) #define repn(i, n) FORN(i, 1, n) #define repr(i, n) FORR(i, n, 0) #define repnr(i, n) FORR(i, n, 1) #define co(n) cout << (n) << endl #define cosp(n) cout << (n) << ' ' #define setp(n) cout << fixed << setprecision(n); #define all(s) (s).begin(), (s).end() #define pb push_back #define mp make_pair #define fs first #define sc second typedef long long ll; typedef pair P; const ll INF = 1e9+1; const ll LINF = 1e18+1; const ll MOD = 1e9+7; //const ll MOD = 998244353; const double PI = acos(-1); const double EPS = 1e-9; const int MAX_N = 1e5; vector > tree(MAX_N+1); int dist[MAX_N+1] = {}; int par[MAX_N+1] = {}; int depth[MAX_N+1] = {}; bool fin[MAX_N+1] = {}; void init(int n){ repn(i, n) par[i] = i; } int root(int x){ if(par[x] == x) return x; else return root(par[x]); } bool same_root(int a, int b){ return root(a) == root(b); } void dfs_lca(int n, int p, int d){ depth[n] = d; par[n] = p; for(int i : tree[n]){ if(depth[i] == INF) dfs_lca(i, n, d+1); } } void build(int n){ fill_n(depth, n+1, INF); repn(i, n) if(par[i] == i) dfs_lca(i, i, 0); } int lca(int a, int b){ if(a == b) return a; if(depth[a] > depth[b]) return lca(par[a], b); if(depth[a] < depth[b]) return lca(a, par[b]); return lca(par[a], par[b]); } void dfs_dist(int n, int p, int d){ for(int i : tree[n]){ if(i != p){ dist[i] += d+1; dfs_dist(i, n, d+1); } } } void dfs(int n, int &m){ m = min(m, dist[n]); fin[n] = true; for(int i : tree[n]){ if(!fin[i]) dfs(i, m); } } int main(void){ int n, m, q; cin >> n >> m >> q; init(n); rep(i, m){ int a, b; cin >> a >> b; tree[a].pb(b); tree[b].pb(a); } build(n); ll ans = 0; rep(i, q){ int a, b; cin >> a >> b; if(same_root(a, b)) ans += depth[a]+depth[b]-2*depth[lca(a, b)]; else{ dfs_dist(a, 0, 0); dfs_dist(b, 0, 0); } } repn(i, n){ int m = INF; if(!fin[i]) dfs(i, m); if(m != INF) ans += m; } co(ans); return 0; }