#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]; bool fin[MAX_N+1]; void init(int n){ for(int i = 0; i <= n; i++) par[i] = i; } int find(int x){ if(par[x] == x) return x; else return par[x] = find(par[x]); } bool same(int x, int y){ return find(x) == find(y); } void union_root(int x, int y){ x = find(x); y = find(y); if(x != y) par[x] = y; } void wfs(int n, int p, int d){ for(int i : tree[n]){ if(i != p){ dist[i] += d+1; wfs(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 measure(int n, int p, int g, int d){ int dd = 0; for(int i : tree[n]){ if(i == g) return d+1; if(i != p){ dd = measure(i, n, g, d+1); } } return dd; } 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); union_root(a, b); } ll ans = 0; rep(i, q){ int a, b; cin >> a >> b; if(!same(a, b)){ wfs(a, 0, 0); wfs(b, 0, 0); }else ans += measure(a, 0, b, 0); } rep(i, n){ int m = INF; if(!fin[i]) dfs(i, m); if(m != INF) ans += m; } co(ans); return 0; }