#include <bits/stdc++.h>
using namespace std;
int n, U, V;
vector<vector<int> > adj;
vector<pair<int, int> > save;
void dfs(int v, int par, int dist) {
  bool leaf = true;
  for (auto u : adj[v]) {
    if (par != u) {
      leaf = false;
      dfs(u, v, dist + 1);
    }
  }
  if (leaf) {
    save.emplace_back(v, dist);
  }
}
int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n >> U >> V;
  adj.resize(n + 1);
  for (int i = 0; i < (int)(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if (adj[U].size() == 1) {
    save.emplace_back(U, 0);
  }
  dfs(U, 0, 0);
  int sz = save.size();
  vector<int> aDist(n + 1, 1000000);
  aDist[V] = 0;
  queue<int> Q;
  Q.push(V);
  while (Q.size()) {
    int v = Q.front();
    Q.pop();
    for (auto u : adj[v]) {
      if (aDist[u] == 1000000) {
        aDist[u] = aDist[v] + 1;
        Q.push(u);
      }
    }
  }
  int maxi = -1, m2 = -1;
  for (int i = 0; i < (int)(sz); i++) {
    int v, dist;
    tie(v, dist) = save[i];
    if (aDist[v] > dist && dist > maxi) {
      maxi = dist;
      m2 = aDist[v];
    }
  }
  cout << m2 - 1 << endl;
  return 0;
}
