#include <bits/stdc++.h>
using namespace std;
using namespace std;
inline int toInt(string s) {
  int v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
inline int readInt() {
  int x;
  scanf("%d", &x);
  return x;
}
const double EPS = 1E-8;
const int INF = 100000000;
struct Edge {
  int to, from;
  long long cost;
  Edge(int from, int to, long long cost) : from(from), to(to), cost(cost) {}
};
class UnionFind {
 public:
  vector<long long> par;
  vector<long long> siz;
  vector<long long> maxv;
  UnionFind(long long sz_) : par(sz_), siz(sz_, 1LL) {
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  void init(long long sz_) {
    par.resize(sz_);
    siz.assign(sz_, 1LL);
    for (long long i = 0; i < sz_; ++i) par[i] = i;
  }
  long long root(long long x) {
    while (par[x] != x) {
      x = par[x] = par[par[x]];
    }
    return x;
  }
  bool merge(long long x, long long y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (siz[x] < siz[y]) swap(x, y);
    siz[x] += siz[y];
    par[y] = x;
    return true;
  }
  bool issame(long long x, long long y) { return root(x) == root(y); }
  long long size(long long x) { return siz[root(x)]; }
};
vector<vector<Edge>> graph;
long long mod_pow(long long x, long long n, long long mod) {
  long long res = 1;
  bool c = false;
  while (n) {
    if (n & 1) res = res * x;
    if (res > mod) {
      c = true;
      res %= mod;
    }
    x = x * x % mod;
    n >>= 1;
  }
  if (c) return mod;
  return res;
}
bool sieve[5000000 + 10];
void make_sieve() {
  for (int i = 0; i < 5000000 + 10; ++i) sieve[i] = true;
  sieve[0] = sieve[1] = false;
  for (int i = 2; i * i < 5000000 + 10; ++i)
    if (sieve[i])
      for (int j = 2; i * j < 5000000 + 10; ++j) sieve[i * j] = false;
}
bool isprime(long long n) {
  if (n == 0 || n == 1) return false;
  for (long long i = 2; i * i <= n; ++i)
    if (n % i == 0) return false;
  return true;
}
template <typename T>
vector<T> gauss_jordan(const vector<vector<T>>& A, const vector<T>& b) {
  int n = A.size();
  vector<vector<T>> B(n, vector<T>(n + 1));
  for (int i = 0; i < n; ++i) {
    for (int j = 0; j < n; ++j) {
      B[i][j] = A[i][j];
    }
  }
  for (int i = 0; i < n; ++i) B[i][n] = b[i];
  for (int i = 0; i < n; ++i) {
    int pivot = i;
    for (int j = i; j < n; ++j) {
      if (abs(B[j][i]) > abs(B[pivot][i])) pivot = j;
    }
    swap(B[i], B[pivot]);
    if (abs(B[i][i]) < EPS) return vector<T>();
    for (int j = i + 1; j <= n; ++j) B[i][j] /= B[i][i];
    for (int j = 0; j < n; ++j) {
      if (i != j) {
        for (int k = i + 1; k <= n; ++k) B[j][k] -= B[i][j] * B[i][k];
      }
    }
  }
  vector<T> x(n);
  for (int i = 0; i < n; ++i) x[i] = B[i][n];
  return x;
}
vector<vector<long long>> mul(vector<vector<long long>>& A,
                              vector<vector<long long>>& B) {
  vector<vector<long long>> C(A.size(), vector<long long>((int)B[0].size()));
  for (int i = 0; i < A.size(); ++i) {
    for (int k = 0; k < B.size(); ++k) {
      for (int j = 0; j < B[0].size(); ++j) {
        C[i][j] = (C[i][j] + A[i][k] * B[k][j] % 1000000007) % 1000000007;
      }
    }
  }
  return C;
}
vector<vector<long long>> mat_pow(vector<vector<long long>> A, long long n) {
  vector<vector<long long>> B(A.size(), vector<long long>((int)A.size()));
  for (int i = 0; i < A.size(); ++i) {
    B[i][i] = 1;
  }
  while (n > 0) {
    if (n & 1) B = mul(B, A);
    A = mul(A, A);
    n >>= 1;
  }
  return B;
}
bool operator<(const pair<int, int>& a, const pair<int, int>& b) {
  if (a.first == b.first) return a.second < b.second;
  return a.first < b.first;
}
const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % 1000000007;
    inv[i] = 1000000007 - inv[1000000007 % i] * (1000000007 / i) % 1000000007;
    finv[i] = finv[i - 1] * inv[i] % 1000000007;
  }
}
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % 1000000007) % 1000000007;
}
int bit[1000010];
int sums(int i) {
  i++;
  int s = 0;
  while (i > 0) {
    s += bit[i];
    i -= i & -i;
  }
  return s;
}
void add(int i, int x) {
  i++;
  while (i <= 1000010) {
    bit[i] += x;
    i += i & -i;
  }
}
long long extGCD(long long a, long long b, long long& x, long long& y) {
  if (b == 0) {
    x = 1;
    y = 0;
    return a;
  }
  long long d = extGCD(b, a % b, y, x);
  y -= a / b * x;
  return d;
}
long long GCD(long long a, long long b) {
  if (b == 0) return a;
  return GCD(b, a % b);
}
struct BipartiteMatching {
  vector<vector<int>> graph;
  vector<int> match, alive, used;
  int timestamp;
  BipartiteMatching(int n)
      : graph(n), alive(n, 1), used(n, 0), match(n, -1), timestamp(0) {}
  void add_edge(int u, int v) {
    graph[u].push_back(v);
    graph[v].push_back(u);
  }
  bool dfs(int idx) {
    used[idx] = timestamp;
    for (auto& to : graph[idx]) {
      int to_match = match[to];
      if (alive[to] == 0) continue;
      if (to_match == -1 || (used[to_match] != timestamp && dfs(to_match))) {
        match[idx] = to;
        match[to] = idx;
        return true;
      }
    }
    return false;
  }
  int bipartite_matching() {
    int ret = 0;
    for (int i = 0; i < graph.size(); i++) {
      if (alive[i] == 0) continue;
      if (match[i] == -1) {
        ++timestamp;
        ret += dfs(i);
      }
    }
    return ret;
  }
  void output() {
    for (int i = 0; i < graph.size(); i++) {
      if (i < match[i]) {
        cout << i << "-" << match[i] << endl;
      }
    }
  }
};
vector<vector<int>> G(100010);
int A[100010], B[100010];
int dist1[100010];
int dist2[100010];
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int N, u, v;
  cin >> N >> u >> v;
  u--;
  v--;
  for (int i = 0; i < (int)N - 1; ++i) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }
  for (int i = 0; i < N; i++) {
    dist1[i] = -1;
    dist2[i] = -1;
  }
  queue<int> q;
  q.push(u);
  dist1[u] = 0;
  while (q.size()) {
    int nv = q.front();
    q.pop();
    for (int i = 0; i < G[nv].size(); i++) {
      int nu = G[nv][i];
      if (dist1[nu] == -1) {
        dist1[nu] = dist1[nv] + 1;
        q.push(nu);
      }
    }
  }
  int ans1 = 0;
  queue<int> q2;
  q2.push(v);
  dist2[v] = 0;
  while (q2.size()) {
    int nv = q2.front();
    q2.pop();
    for (int i = 0; i < G[nv].size(); i++) {
      int nu = G[nv][i];
      if (dist1[nu] == dist2[nv] + 1) {
        ans1 = max(ans1, dist1[nu]);
        continue;
      }
      if (dist2[nu] == -1) {
        dist2[nu] = dist2[nv] + 1;
        q2.push(nu);
      }
    }
  }
  for (int i = 0; i < N; i++) {
    ans1 = max(ans1, dist2[i] - 1);
  }
  cout << ans1 << endl;
  return 0;
}
