#include <bits/stdc++.h>
using namespace std;
const int inf = 1001001001;
vector<vector<int> > Graph;
int da[100000];
int dt[100000];
void dfs(int v, int p, int dist) {
  for (auto e : Graph[v]) {
    dt[e] = dist;
    if (e == p)
      continue;
    else
      dfs(e, v, dist + 1);
  }
}
int main() {
  int n, u, v;
  fill(dt, dt + 10000, inf);
  cin >> n >> u >> v;
  u--;
  v--;
  Graph.assign(n, vector<int>());
  for (int i = 0; i < (n - 1); ++i) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    Graph[a].push_back(b);
    Graph[b].push_back(a);
  }
  vector<int> dist(n, -1);
  vector<int> dist2(n, -1);
  queue<int> que;
  dist[u] = 0;
  que.push(u);
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int nv : Graph[p]) {
      if (dist[nv] != -1) continue;
      dist[nv] = dist[p] + 1;
      que.push(nv);
    }
  }
  dist2[v] = 0;
  que.push(v);
  while (!que.empty()) {
    int p = que.front();
    que.pop();
    for (int nv : Graph[p]) {
      if (dist2[nv] != -1) continue;
      dist2[nv] = dist2[p] + 1;
      que.push(nv);
    }
  }
  int max_dist = 0;
  for (int i = 0; i < (n); ++i) {
    if (dist2[i] - dist[i] >= 0) {
      if (max_dist < dist[i]) {
        max_dist = dist[i];
      }
    }
    if (dist2[i] == dist[i]) {
      for (int nv : Graph[i]) {
        if (dist[nv] == dist2[nv]) dist[nv] = -1;
      }
    }
  }
  cout << max_dist << endl;
}
