#include <bits/stdc++.h>
using namespace std;
const int INF = INT_MAX;
vector<vector<int> > g;
int N;
void swap(long long &a, long long &b) {
  long long temp = a;
  a = b;
  b = temp;
}
long long gcd(long long a, long long b) {
  while (b) {
    a %= b;
    swap(a, b);
  }
  return a;
}
long long lcm(long long a, long long b) {
  long long ans = (a * b) / gcd(a, b);
  return ans;
}
vector<int> bfs(int s) {
  vector<int> distance(N + 1, INT_MAX);
  distance[s] = 0;
  queue<int> q;
  q.push(s);
  while (!q.empty()) {
    int temp = q.front();
    q.pop();
    for (int i = 0; i < g[temp].size(); i++) {
      if (distance[g[temp][i]] == INT_MAX) {
        q.push(g[temp][i]);
        distance[g[temp][i]] = distance[temp] + 1;
      }
    }
  }
  return distance;
}
int main() {
  int u, v;
  cin >> N >> u >> v;
  g.resize(N + 1);
  for (int i = 1; i < N; i++) {
    int x, y;
    cin >> x >> y;
    if (x == u && y == v) {
      cout << (0) << endl;
      return 0;
    }
    if (x == v && y == u) {
      cout << (0) << endl;
      return 0;
    }
    g[x].push_back(y);
    g[y].push_back(x);
  }
  vector<int> o1(N + 1);
  o1 = bfs(u);
  vector<int> o2(N + 2);
  o2 = bfs(v);
  int ans = 1;
  if (u == v) {
    cout << (0) << endl;
    return 0;
  }
  for (int i = 1; i <= N; i++) {
    if (g[i].size() == 1 && o1[i] == o2[i] - 1) {
      ans = max(ans, o1[i]);
    }
  }
  cout << (ans) << endl;
  return 0;
}
