#include using namespace std; using ll=long long; #define int ll #define rng(i,a,b) for(int i=int(a);i=int(a);i--) #define per(i,b) gnr(i,0,b) #define pb push_back #define eb emplace_back #define a first #define b second #define bg begin() #define ed end() #define all(x) x.bg,x.ed #ifdef LOCAL #define dmp(x) cerr<<__LINE__<<" "<<#x<<" "< void chmax(t&a,u b){if(a void chmin(t&a,u b){if(b using vc=vector; template using vvc=vc>; using pi=pair; using vi=vc; template ostream& operator<<(ostream& os,const pair& p){ return os<<"{"< ostream& operator<<(ostream& os,const vc& v){ os<<"{"; for(auto e:v)os< void print_tuple(ostream&,const T&){ } template void print_tuple(ostream&os,const T&t){ if(i)os<<","; os<(t); print_tuple(os,t); } template ostream& operator<<(ostream&os,const tuple&t){ os<<"{"; print_tuple<0,tuple,Args...>(os,t); return os<<"}"; } void print(ll x,int suc=1){ cout<>i; return i; } vi readvi(int n,int off=0){ vi v(n); rep(i,n)v[i]=read()+off; return v; } template void print(const vector&v,int suc=1){ rep(i,v.size()) print(v[i],i==int(v.size())-1?suc:2); } string readString(){ string s; cin>>s; return s; } template T sq(const T& t){ return t*t; } //#define CAPITAL void yes(bool ex=true){ #ifdef CAPITAL cout<<"YES"< void mkuni(vc&v){ sort(all(v)); v.erase(unique(all(v)),v.ed); } ll rand_int(ll l, ll r) { //[l, r] #ifdef LOCAL static mt19937_64 gen; #else static random_device rd; static mt19937_64 gen(rd()); #endif return uniform_int_distribution(l, r)(gen); } //KUPC2017J //AOJDSL1A //without rank struct unionfind{ vi p,s; int c; unionfind(int n):p(n,-1),s(n,1),c(n){} int find(int a){ return p[a]==-1?a:(p[a]=find(p[a])); } //set b to a child of a bool unite(int a,int b){ a=find(a); b=find(b); if(a==b)return false; p[b]=a; s[a]+=s[b]; c--; return true; } bool same(int a,int b){ return find(a)==find(b); } int sz(int a){ return s[find(a)]; } }; //CF530F //CodeChef Persistent Oak //AOJ GRL5C template struct HLD{ vvc g; int n,rt,cnt; vi sub,in,out,par,head,dep; int dfs1(int v,int p,int d){ par[v]=p; dep[v]=d; g[v].erase(remove(all(g[v]),p),g[v].ed); for(auto&e:g[v]){ sub[v]+=dfs1(e,v,d+1); if(sub[g[v][0]]&gg,int rr):g(gg),n(g.size()),rt(rr),cnt(0), sub(n,1),in(n),out(n),par(n,-1),head(n),dep(n){ dfs1(rt,-1,0); dfs2(rt,rt); } int lca(int a,int b){ while(head[a]!=head[b]){ if(dep[head[a]]>dep[head[b]]) swap(a,b); b=par[head[b]]; } if(dep[a]>dep[b]) swap(a,b); return a; } int len(int a,int b){ return dep[a]+dep[b]-dep[lca(a,b)]*2; } }; //AGC034E //int(E)->to template struct treedp{ const vvc& g; vvc dp1,dp2; vc res; N dfs1(int v,int p){ N tmp;tmp.init(v); dp1[v].pb(tmp); E up; for(auto e:g[v]) if(e!=p) dp1[v].pb(dfs1(e,v)); else up=e; dp2[v]=dp1[v]; rng(i,1,dp2[v].size()) dp2[v][i]=dp2[v][i-1]+dp2[v][i]; if(p==-1)return N(); else return dp2[v].back().up(up); } void dfs2(int v,int p,N cur){ res[v]=cur+dp2[v].back(); per(i,g[v].size()){ auto e=g[v][i]; if(e==p)continue; dp2[v].pop_back(); dfs2(e,v,(cur+dp2[v].back()).up(e)); cur=cur+dp1[v].back(); dp1[v].pop_back(); } } treedp(const vvc&gg):g(gg),dp1(g.size()),dp2(g.size()),res(g.size()){ dfs1(0,-1); N tmp;tmp.init(0); dfs2(0,-1,tmp); } }; //usage vi cnt; struct N{ int v,c,s; void init(int vv){ v=vv; c=cnt[v]; s=0; } N up(int to)const{ return N{to,c+cnt[to],s+c}; } N operator+(const N&r)const{ assert(v==r.v); return N{v,c+r.c-cnt[v],s+r.s}; } }; int calc(vi vs,vc es,vc qs1,vi qs2){ int n=vs.size(); vvc g(n); for(auto e:es){ int a=lower_bound(all(vs),e.a)-vs.bg; int b=lower_bound(all(vs),e.b)-vs.bg; g[a].pb(b); g[b].pb(a); } auto hld=HLD(g,0); int ans=0; for(auto p:qs1){ int a=lower_bound(all(vs),p.a)-vs.bg; int b=lower_bound(all(vs),p.b)-vs.bg; ans+=hld.len(a,b); } cnt.assign(n,0); for(auto v:qs2){ int a=lower_bound(all(vs),v)-vs.bg; cnt[a]++; } auto res=treedp(g).res; int mn=inf; rep(i,n)chmin(mn,res[i].s); return ans+mn; } signed main(){ cin.tie(0); ios::sync_with_stdio(0); cout<>n>>m>>q; unionfind uf(n); vc es; rep(_,m){ int a,b;cin>>a>>b; a--;b--; es.eb(a,b); uf.unite(a,b); } vvc vs(n); vvc es2(n); vvc qs1(n); vvc qs2(n); rep(i,n)vs[uf.find(i)].pb(i); for(auto e:es)es2[uf.find(e.a)].pb(e); rep(_,q){ int a,b;cin>>a>>b; a--;b--; if(uf.same(a,b)){ qs1[uf.find(a)].eb(a,b); }else{ qs2[uf.find(a)].pb(a); qs2[uf.find(b)].pb(b); } } int ans=0; rep(i,n)if(uf.find(i)==i) ans+=calc(vs[i],es2[i],qs1[i],qs2[i]); cout<