#include <bits/stdc++.h>
using namespace std;
inline long long toLong(string s) {
  long long v;
  istringstream sin(s);
  sin >> v;
  return v;
}
template <class T>
inline string toString(T x) {
  ostringstream sout;
  sout << x;
  return sout.str();
}
template <class T>
inline T sqr(T x) {
  return x * x;
}
const double EPS = 1e-5;
const double PI = acos(-1.0);
long long n, u, v;
long long ans = 0;
vector<vector<long long> > link(50001);
vector<pair<long long, long long> > leaf1;
vector<pair<long long, long long> > leaf2;
vector<long long> visited1(50001, 0);
vector<long long> dist1(50001, 0);
void dfs1(long long x, long long d) {
  visited1[x] = 1;
  dist1[x] = d;
  bool isLeaf = true;
  for (long long i = (0); i < (link[x].size()); ++i) {
    long long adj = link[x][i];
    if (!visited1[adj]) {
      isLeaf = false;
      dfs1(adj, d + 1);
    }
  }
  if (isLeaf) {
    leaf1.push_back(make_pair(x, d));
  }
}
vector<long long> visited2(50001, 0);
vector<long long> dist2(50001, 0);
void dfs2(long long x, long long d) {
  visited2[x] = 1;
  dist2[x] = d;
  bool isLeaf = true;
  for (long long i = (0); i < (link[x].size()); ++i) {
    long long adj = link[x][i];
    if (!visited2[adj]) {
      isLeaf = false;
      dfs2(adj, d + 1);
    }
  }
  if (isLeaf) {
    leaf2.push_back(make_pair(x, d));
  }
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> u >> v;
  for (long long i = (0); i < (n - 1); ++i) {
    long long a, b;
    cin >> a >> b;
    link[a].push_back(b);
    link[b].push_back(a);
  }
  dfs1(u, 0);
  dfs2(v, 0);
  for (long long i = (0); i < (leaf2.size()); ++i) {
    long long xv = leaf2[i].first;
    long long dv = leaf2[i].second;
    long long du = dist1[xv];
    if (du < dv) {
      ans = max(ans, dv);
    }
  }
  cout << (ans - 1) << endl;
  ;
}
