#include <bits/stdc++.h>
using namespace std;
long long n;
long long u, v;
vector<vector<long long> > E(111111);
long long node;
vector<long long> ho(111111);
void bfs() {
  queue<int> tak, ao;
  tak.push(u);
  ao.push(v);
  ho[u] = 1;
  ho[v] = 2;
  while (true) {
    if (tak.empty() && ao.empty()) break;
    if (!tak.empty()) {
      long long now = tak.front();
      tak.pop();
      for (auto e : E[now]) {
        if (ho[e] == 2) node = now;
        if (ho[e] == 0) {
          ho[e] = 1;
          tak.push(e);
        }
      }
    }
    if (!ao.empty()) {
      long long now = ao.front();
      ao.pop();
      for (auto e : E[now]) {
        if (ho[e] == 0) {
          ho[e] = 2;
          ao.push(e);
        }
      }
    }
  }
}
vector<long long> vis(111111);
void dfs2(int now, int di, int par) {
  vis[now] = di;
  for (auto a : E[now]) {
    if (a == par || a == node) continue;
    dfs2(a, di + 1, now);
  }
}
vector<long long> vis2(111111);
void dfs3(int now, int di, int par) {
  vis2[now] = di;
  for (auto a : E[now]) {
    if (a == par || vis[a] || a == v) continue;
    dfs3(a, di + 1, now);
  }
}
vector<long long> vis3(111111);
void dfs4(int now, int di, int par) {
  vis3[now] = di;
  for (auto a : E[now]) {
    if (a == par) continue;
    dfs4(a, di + 1, now);
  }
}
vector<long long> vis4(111111);
void dfs5(int now, int di, int par) {
  vis4[now] = di;
  for (auto a : E[now]) {
    if (a == par) continue;
    dfs5(a, di + 1, now);
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  cin >> u >> v;
  u--;
  v--;
  for (int i = 0; i < n - 1; i++) {
    long long a, b;
    cin >> a >> b;
    E[--a].push_back(--b);
    E[b].push_back(a);
  }
  bfs();
  dfs3(node, 0, -1);
  dfs4(u, 0, -1);
  dfs5(v, 0, -1);
  long long ma = 0, ma2 = 0;
  long long po = -1, po2 = -1;
  for (int i = 0; i < n; i++) {
    if (vis4[i]) {
      ma = max(vis4[i], ma);
    }
  }
  cout << max(ma, ma2) - 1 << endl;
  return 0;
}
