import os,sys,random,threading #sys.exit() 退出程序 #sys.setrecursionlimit(10**6) #调整栈空间 from random import randint,choice,shuffle #randint(a,b)从[a,b]范围随机选择一个数 #choice(seq)seq可以是一个列表,元组或字符串,从seq中随机选取一个元素 #shuffle(x)将一个可变的序列x中的元素打乱 from copy import deepcopy from io import BytesIO,IOBase from types import GeneratorType from functools import lru_cache,reduce #reduce(op,迭代对象) from bisect import bisect_left,bisect_right #bisect_left(x) 大于等于x的第一个下标 #bisect_right(x) 大于x的第一个下标 from collections import Counter,defaultdict,deque from itertools import accumulate,combinations,permutations #accumulate(a)用a序列生成一个累积迭代器,一般list化前面放个[0]做前缀和用 #combinations(a,k)a序列选k个 组合迭代器 #permutations(a,k)a序列选k个 排列迭代器 from heapq import heapify,heappop,heappush #heapify将列表转为堆 from typing import Generic,Iterable,Iterator,TypeVar,Union,List from string import ascii_lowercase,ascii_uppercase,digits #小写字母,大写字母,十进制数字 from math import ceil,floor,sqrt,pi,factorial,gcd,log,log10,log2,inf #ceil向上取整,floor向下取整 ,sqrt开方 ,factorial阶乘 from decimal import Decimal,getcontext #Decimal(s) 实例化Decimal对象,一般使用字符串 #getcontext().prec=100 修改精度 from sys import stdin, stdout, setrecursionlimit input = lambda: sys.stdin.readline().rstrip("\r\n") MI = lambda :map(int,input().split()) li = lambda :list(MI()) ii = lambda :int(input()) mod = int(1e9 + 7) #998244353 inf = 1<<60 py = lambda :print("YES") pn = lambda :print("NO") DIRS = [(0, 1), (1, 0), (0, -1), (-1, 0)] # 右下左上 DIRS8 = [(0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1), (-1, 0),(-1, 1)] # →↘↓↙←↖↑↗ class HLD: def __init__(self, g, root): #无论是点还是dfn还是dep,都从1开始,默认0是无 n=len(g) self.g=g self.fa=[0]*(n+5) #父节点,0表示无父节点 self.size=[1]*(n+5) #子树大小 self.dep=[0]*(n+5) #深度,根深度为1 self.son=[0]*(n+5) #重儿子,0表示无儿子 self.dfn=[0]*(n+5) #dfs序,子树终点的dfs序是dfn[i]+size[i]-1 self.top=[0]*(n+5) #所在重链起点,起点就是自己 self.rank=[0]*(n+5) #dfs序为i的节点编号 fa=self.fa;size=self.size;dep=self.dep;son=self.son dfn=self.dfn;top=self.top;rank=self.rank stk=[[root,0,0]] #node,flag,fa dep[root]=1 while stk: u,flag,father=stk.pop() if flag: for v in g[u]: if v!=father: size[u]+=size[v] if son[u]==0 or size[v]>size[son[u]]: son[u]=v else: stk.append([u,1,father]) for v in g[u]: if v!=father: stk.append([v,0,u]) fa[v]=u dep[v]=dep[u]+1 stk=[[root,root]] tot=1 while stk: u,tops=stk.pop() dfn[u]=tot rank[tot]=u tot+=1 top[u]=tops if son[u]==0: continue for v in g[u]: if v!=fa[u] and v!=son[u]: stk.append([v,v]) stk.append([son[u],tops]) def lca(self,u,v): #求u和v的最近公共祖先节点 fa=self.fa;size=self.size;dep=self.dep;son=self.son dfn=self.dfn;top=self.top;rank=self.rank while top[u]!=top[v]: if dep[top[u]]>dep[top[v]]: u=fa[top[u]] else: v=fa[top[v]] return v if dep[u]>dep[v] else u def dis(self,u,v): dep=self.dep return dep[u]+dep[v]-2*dep[self.lca(u,v)] def kth_fa(self,root,k): #求root节点的第k个祖先 fa=self.fa;size=self.size;dep=self.dep;son=self.son dfn=self.dfn;top=self.top;rank=self.rank if k>=dep[root]: #无第k个祖先返回-1 return -1 while True: u=top[root] if dfn[root]-k>=dfn[u]: return rank[dfn[root]-k] k-=dfn[root]-dfn[u]+1 root=fa[u] def route_query(self,u,v): #查询u到v简单路径 fa=self.fa;size=self.size;dep=self.dep;son=self.son dfn=self.dfn;top=self.top;rank=self.rank route=[] while top[u]!=top[v]: if dep[top[u]]dep[v]: u,v=v,u route.append((dfn[u],dfn[v])) return route def path(self,start,end): #得到start到end简单路径的所有节点 fa=self.fa;size=self.size;dep=self.dep;son=self.son dfn=self.dfn;top=self.top;rank=self.rank mid=self.lca(start,end) ps=[] while start!=mid: ps.append(start) start=fa[start] pe=[] while end!=mid: pe.append(end) end=fa[end] return ps+[mid]+pe[::-1] def bootstrap(f, stack=[]): #yield def wrappedfunc(*args, **kwargs): if stack: return f(*args, **kwargs) else: to = f(*args, **kwargs) while True: if type(to) is GeneratorType: stack.append(to) to = next(to) else: stack.pop() if not stack: break to = stack[-1].send(to) return to return wrappedfunc def find(x): t=x while fa[x]!=x: x=fa[x] while t!=x: fa[t],t=x,fa[t] return x n,m,q=li() fa=list(range(n+1)) g=[[] for _ in range(n+2)] for _ in range(m): u,v=li() g[u]+=[v] g[v]+=[u] fu=find(u) fv=find(v) fa[fv]=fu for i in range(1,n+1): if find(i)==i: g[n+1].append(i) hld=HLD(g,n+1) cnt=[0]*(n+1) res=0 for _ in range(q): u,v=li() if find(u)==find(v): res+=hld.dis(u,v) else: cnt[u]+=1 cnt[v]+=1 f=[0]*(n+1) h=[0]*(n+1) @bootstrap def dfs(u,fa): h[u]=cnt[u] for v in g[u]: if v==fa: continue yield dfs(v,u) f[u]+=f[v]+h[v] h[u]+=h[v] yield None @bootstrap def dfs2(u,fa): global ans tf=0 th=cnt[u] for v in g[u]: tf+=f[v]+h[v] th+=h[v] ans=min(ans,tf) for v in g[u]: if v==fa: continue f[u]=tf-f[v]-h[v] h[u]=th-h[v] yield dfs2(v,u) yield None for i in range(1,n+1): if find(i)==i: ans=inf dfs(i,-1) dfs2(i,-1) res+=ans print(res)