import sys # sys.setrecursionlimit(200005) int1 = lambda x: int(x)-1 pDB = lambda *x: print(*x, end="\n", file=sys.stderr) p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr) def II(): return int(sys.stdin.readline()) def LI(): return list(map(int, sys.stdin.readline().split())) def LLI(rows_number): return [LI() for _ in range(rows_number)] def LI1(): return list(map(int1, sys.stdin.readline().split())) def LLI1(rows_number): return [LI1() for _ in range(rows_number)] def SI(): return sys.stdin.readline().rstrip() dij = [(0, 1), (-1, 0), (0, -1), (1, 0)] # dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)] inf = (1 << 63)-1 # inf = (1 << 31)-1 md = 10**9+7 # md = 998244353 class UnionFind: def __init__(self, n): self.state = [-1]*n self.size_table = [1]*n # cntはグループ数 self.cnt = n def root(self, u): stack = [] while self.state[u] >= 0: stack.append(u) u = self.state[u] for v in stack: self.state[v] = u return u def same(self, u, v): return self.root(u) == self.root(v) def merge(self, u, v): u = self.root(u) v = self.root(v) if u == v: return False du = -self.state[u] dv = -self.state[v] if du < dv: u, v = v, u if du == dv: self.state[u] -= 1 self.state[v] = u self.cnt -= 1 self.size_table[u] += self.size_table[v] return True # グループの要素数 def size(self, u): return self.size_table[self.root(u)] class LCA: # 頂点は0~n-1 def __init__(self, parents, depth): self.n = len(parents) self.parents = parents self.depth = depth self.max_level = max(self.depth).bit_length() self.ancestor = [self.parents]+[[-1]*self.n for _ in range(self.max_level)] row0 = self.ancestor[0] for lv in range(self.max_level): row1 = self.ancestor[lv+1] for u in range(self.n): row1[u] = row0[row0[u]] row0 = row1 # 最小共通祖先 def anc(self, u, v): diff = self.depth[u]-self.depth[v] if diff < 0: u, v = v, u diff = abs(diff) lv = 0 while diff: if diff & 1: u = self.ancestor[lv][u] lv, diff = lv+1, diff >> 1 if u == v: return u for lv in range(self.depth[u].bit_length()-1, -1, -1): anclv = self.ancestor[lv] if anclv[u] != anclv[v]: u, v = anclv[u], anclv[v] return self.parents[u] n, m, q = LI() e = lambda: [0, 0] # 単位元 par = [-1]*n depth = [0]*n uf = UnionFind(n) to = [[] for _ in range(n)] for _ in range(m): u, v = LI1() to[u].append(v) to[v].append(u) uf.merge(u, v) dp = [e() for _ in range(n)] rdp = [e() for _ in range(n)] ab = [] for _ in range(q): a, b = LI1() if uf.same(a, b): ab.append((a, b)) else: dp[a][0] += 1 dp[b][0] += 1 def op(a, b): return [a[0]+b[0], a[1]+b[1]] def trans_up(u): dp[u][1] += dp[u][0] return def trans_down(u): rdp[u][1] += rdp[u][0] return # dfs順を作る def reroot(root): uu = [] stack = [root] while stack: u = stack.pop() uu.append(u) vv = [] for v in to[u]: if v == par[u]: continue vv.append(v) par[v] = u stack.append(v) rdp[v] = dp[u][:] depth[v] = depth[u]+1 to[u] = vv # pDB(uu) # pDB(dp) # pDB(rdp) # 下から更新 for u in uu[::-1]: p = par[u] if p != -1: trans_up(u) dp[p] = op(dp[p], dp[u]) # 上から更新 for u in uu: cs = e() # ↓変数注意 for v in to[u]: rdp[v] = op(rdp[v], cs) cs = op(cs, dp[v]) cs = op(e(), rdp[u]) for v in to[u][::-1]: rdp[v] = op(rdp[v], cs) trans_down(v) cs = op(cs, dp[v]) dp[u] = cs return min(dp[u][1] for u in uu) ans = 0 for u in range(n): if par[u] != -1: continue ans += reroot(u) # pDB(dp, ans) lca = LCA(par, depth) for u, v in ab: a = lca.anc(u, v) ans += depth[u]+depth[v]-depth[a]*2 print(ans) # pDB(dp) # pDB(par)