import sequtils, strutils proc fill(g: seq[seq[int]], i, p, r: int, root, dep: var seq[int]) = root[i] = r for j in g[i]: if j != p: dep[j] = dep[i] + 1 fill(g, j, i, r, root, dep) proc calc(g: seq[seq[int]], i, p: int, freq: seq[int64], cnt: var seq[int64]) = cnt[i] = freq[i] for j in g[i]: if j != p: calc(g, j, i, freq, cnt) cnt[i] += cnt[j] proc solve(g: seq[seq[int]], i, p, r: int, d: int64, cnt: seq[int64], mn: var int64) = mn = min(mn, d) for j in g[i]: if j != p: solve(g, j, i, r, d - cnt[j] + (cnt[r] - cnt[j]), cnt, mn) proc calc_par(g: seq[seq[int]], i, p: int, ppar: var seq[seq[int]]) = ppar[0][i] = p for j in g[i]: if j != p: calc_par(g, j, i, ppar) proc get_lca(aa, bb, r: int, dep: seq[int], ppar: seq[seq[int]]):int = var (a, b) = (aa, bb) if dep[a] > dep[b]: swap(a, b) for j in 0..<20: if (((dep[b] - dep[a]) shr j) and 1) == 1: b = ppar[j][b] if a == b: return a for j in countdown(19, 0): if ppar[j][a] != ppar[j][b]: a = ppar[j][a] b = ppar[j][b] return ppar[0][a] proc main() = var n, m, q: int (n, m, q) = stdin.readLine.strip.split.map(parseInt) var g = newSeqWith(n, newSeq[int]()) for i in 0..= 0: ppar[j + 1][i] = ppar[j][p] for p in pts: let (a, b) = p if root[a] == root[b]: let c = get_lca(a, b, root[a], dep, ppar) ans += dep[a] + dep[b] - dep[c] * 2 echo ans main()