#include <bits/stdc++.h>
using namespace std;
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1LL << 62;
const long long MOD = 1e9 + 7;
bool greaterSecond(const pair<int, int> &f, const pair<int, int> &s) {
  return f.second > s.second;
}
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return a / gcd(a, b) * b; }
long long nCr(long long n, long long r) {
  if (r == 0 || r == n) {
    return 1;
  } else if (r == 1) {
    return n;
  }
  return (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
long long nPr(long long n, long long r) {
  r = n - r;
  long long ret = 1;
  for (long long i = n; i >= r + 1; i--) ret *= i;
  return ret;
}
int n;
int ans = 0;
vector<int> bfs(int s, vector<vector<int>> &g) {
  vector<int> res(n, -1);
  queue<pair<int, int>> q;
  q.push({s, 0});
  res[s] = 0;
  while (!q.empty()) {
    int now = q.front().first;
    int nowdist = q.front().second;
    q.pop();
    for (int i = 0; i < (int)(g[now].size()); i++) {
      int next = g[now][i];
      int nextdist = nowdist + 1;
      if (res[next] != -1) continue;
      res[next] = nextdist;
      q.push({next, nextdist});
    }
  }
  return res;
}
int bfs2(int s, vector<vector<int>> &g, vector<int> &adist, int &a) {
  vector<int> dist(n, -1);
  queue<pair<int, int>> q;
  q.push({s, 0});
  while (!q.empty()) {
    int now = q.front().first;
    int nowdist = q.front().second;
    q.pop();
    for (int i = 0; i < (int)(g[now].size()); i++) {
      int next = g[now][i];
      int nextdist = nowdist + 1;
      if (dist[next] != -1) continue;
      if (adist[next] < nextdist) continue;
      dist[next] = nextdist;
      q.push({next, nextdist});
    }
  }
  int ma = 0;
  int idx = a;
  for (int i = 0; i < (int)(n); i++) {
    if (dist[i] > ma) {
      idx = i;
      ma = dist[i];
    }
  }
  int res = adist[idx];
  if (idx != a) res--;
  return res;
}
int main(void) {
  int t, a;
  cin >> n >> t >> a;
  t--;
  a--;
  vector<vector<int>> g(n);
  vector<int> dist(n, 0);
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> adist = bfs(a, g);
  cout << bfs2(t, g, adist, a) << endl;
}
