from strutils import parseInt, split
from sequtils import map, mapIt, newSeqWith, zip, filterIt

let
  (N, u, v) = block:
    let t = stdin.readLine.split.map(parseInt)
    (t[0], t[1] - 1, t[2] - 1)
  graph = block:
    var result = newSeqWith(N, newSeq[int]())
    for _ in 0..<(N - 1):
      let AB = stdin.readLine.split.mapIt(it.parseInt - 1)
      result[AB[0]].add(AB[1])
      result[AB[1]].add(AB[0])
    result

proc dfs(v: int; dists: var seq[int]; dist = 0) =
  dists[v] = dist
  for u in graph[v]:
    if dists[u] < 0:
      dfs(u, dists, dist + 1)

var dists = (fromU: newSeqWith(N, -1), fromV: newSeqWith(N, -1))
dfs(u, dists.fromU)
dfs(v, dists.fromV)

echo zip(dists.fromU, dists.fromV).filterIt(it.a < it.b).mapIt(it.b).max - 1
