#include #include #include #include #include #include #include #include #include #include #define mkp make_pair #define mkt make_tuple #define rep(i,n) for(int i = 0; i < (n); ++i) using namespace std; typedef long long ll; const ll MOD=1e9+7; int N,M,Q; vector U,V; vector A,B; vector g[100010]; ll num[100010]; ll child[100010]; int used[100010]; #define MAX_LOG_V 21 #define MAX_V 100010 int parent[MAX_LOG_V][MAX_V]; //親を2^k回辿って到達する頂点(根を通り過ぎる場合は-1) int depth[MAX_V]; //根からの深さ int root; void dfs(int v,int p,int d){ parent[0][v]=p; depth[v]=d; used[v]=root; for(int i=0;idepth[v]) swap(u,v); for(int k=0;k>k&1){ v=parent[k][v]; } } if(u==v) return u; //二分探索でLCAを求める for(int k=MAX_LOG_V-1;k>=0;k--){ if(parent[k][u]!=parent[k][v]){ u=parent[k][u]; v=parent[k][v]; } } return parent[0][u]; } void setChild(int now,int par){ child[now]=num[now]; for(auto nex:g[now]){ if(par==nex) continue; setChild(nex,now); child[now]+=child[nex]; } } ll eval(int now,int par){ ll res=0; for(auto nex:g[now]){ if(nex==par) continue; ll p=eval(nex,now); res+=p+child[nex]; } return res; } ll global; void rfs(int now,int par,ll val){ global=min(global,val); for(auto nex:g[now]){ if(nex==par) continue; ll nexVal=val-child[nex]+(child[used[now]]-child[nex]); rfs(nex,now,nexVal); } } int main(){ cin>>N>>M>>Q; U.resize(M); V.resize(M); rep(i,M) cin>>U[i]>>V[i]; A.resize(Q); B.resize(Q); rep(i,Q) cin>>A[i]>>B[i]; rep(i,M){ U[i]--;V[i]--; g[U[i]].push_back(V[i]); g[V[i]].push_back(U[i]); } rep(i,N) used[i]=-1; rep(i,N){ if(used[i]!=-1) continue; root=i; dfs(i,-1,0); } init(N); ll ans=0; rep(i,Q){ A[i]--;B[i]--; if(used[A[i]]==used[B[i]]){ ans+=depth[A[i]]+depth[B[i]]-2*depth[lca(A[i],B[i])]; }else{ num[A[i]]++; num[B[i]]++; } } rep(i,N){ if(used[i]!=i) continue; setChild(i,-1); global=eval(i,-1); rfs(i,-1,global); ans+=global; } cout<