#include using namespace std; #define endl '\n' #define ALL(a) (a).begin(),(a).end() #define ALLR(a) (a).rbegin(),(a).rend() #define spa << " " << #define test cout<<"test"<= (ll)(n); i--) using ll = long long; using ld = long double; const ll MOD = 1e9+7; //const ll MOD = 998244353; const ll INF = 1e18; using P = pair; template void chmin(T &a,T b){if(a>b)a=b;} template void chmax(T &a,T b){if(a void ans(bool x,T1 y,T2 z){if(x)cout< void debug(vector>&v,ll h,ll w){for(ll i=0;i&v,ll h,ll w){for(ll i=0;i void debug(vector&v,ll n){if(n!=0)cout< vector>vec(ll x, ll y, T w){ vector>v(x,vector(y,w));return v;} ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;} vectordx={1,0,-1,0,1,1,-1,-1}; vectordy={0,1,0,-1,1,-1,1,-1}; template vector make_v(size_t a,T b){return vector(a,b);} template auto make_v(size_t a,Ts... ts){ return vector(a,make_v(ts...)); } vectorval(110000); struct LCA{ ll datasize = 21; ll n,root;//rootを根とする頂点数nの根付き木 vectordepth;//0から vector>G,data; vectorgroup; vector

dp; ll minbuf,minsum; LCA(vector>g,ll r):G(g),n(g.size()),root(r){ data.assign(n,vector(datasize,-1)); depth.assign(n,-1LL); group.assign(n,-1LL); dp.assign(n,MP(0LL,0LL)); minsum=0; build(); } void build(){ ll cnt=0; rep(i,0,n){ if(depth[i]==-1){ minbuf=INF; dfs(i,0,cnt); cnt++; dfsmin(i,0,MP(dp[i].fi,dp[i].fi+dp[i].se)); minsum+=minbuf; //cout< dfs(ll k,ll d, ll x){ depth[k]=d; group[k]=x; ll num=0; ll sumbuf=0; for(ll i=0;i=0?depth[x]:-1; } ll query(ll x,ll y){ if(depth[x]=1&&depth[y]>=deep(data[x][tmp]))tmp--; x = data[x][tmp]; } tmp = datasize - 1; while(x!=y){ while(tmp>=1&&data[x][tmp]==data[y][tmp])tmp--; x = data[x][tmp]; y = data[y][tmp]; } return x; } }; struct UnionFind { vector data; UnionFind(ll size) : data(size, -1) { } bool unite(ll x, ll y) { x = root(x); y = root(y); if (x != y) { if (data[y] < data[x]) swap(x, y); data[x] += data[y]; data[y] = x; } return x != y; } bool find(ll x, ll y) { return root(x) == root(y); } ll root(ll x) { return data[x] < 0 ? x : data[x] = root(data[x]); } ll size(ll x) { return -data[root(x)]; } }; int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); //cout<>n>>m>>q; vector>g(n); UnionFind uf(n); rep(i,0,m){ ll u,v;cin>>u>>v; u--;v--; g[u].PB(v); g[v].PB(u); uf.unite(u,v); } vector

p; rep(i,0,q){ ll a,b;cin>>a>>b; a--;b--; if(uf.find(a,b))p.EB(a,b); else val[a]++,val[b]++; } LCA lca(g,0); rep(i,0,p.size()){ lca.minsum+=lca.deep(p[i].fi)+lca.deep(p[i].se) -2*lca.deep(lca.query(p[i].fi,p[i].se)); } cout<