#include <bits/stdc++.h>
using namespace std;
class tree {
  int ct;

 public:
  int nn, root;
  vector<int> parent;
  vector<int> depth;
  vector<int> sz;
  vector<vector<int>> adj;
  vector<vector<int>> sons;
  vector<int> in, out;
  vector<int> pos;
  vector<vector<int>> pred;
  int MAXLEVEL;
  tree(int n) {
    nn = n;
    adj.clear();
    adj.resize(n);
  }
  void add_path(int a, int b) {
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  void add_directed_path(int a, int b) { adj[a].push_back(b); }
  void dfs_set_root(int id, bool cartesian_decomposition = false) {
    if (cartesian_decomposition) {
      in[id] = ct;
      pos[ct] = id;
      ct++;
    }
    sz[id]++;
    for (auto p : adj[id]) {
      if (parent[p] == -1) {
        parent[p] = id;
        depth[p] = depth[id] + 1;
        dfs_set_root(p, cartesian_decomposition);
        sz[id] += sz[p];
        sons[id].push_back(p);
      }
    }
    if (cartesian_decomposition) out[id] = ct - 1;
  }
  void set_root(int id, bool cartesian_decomposition = false) {
    if (cartesian_decomposition) {
      in.resize(nn);
      out.resize(nn);
      pos.resize(nn);
      ct = 0;
    }
    parent.assign(nn, -1);
    depth.assign(nn, -1);
    sz.assign(nn, 0);
    sons.clear();
    sons.resize(nn);
    parent[id] = 0;
    depth[id] = 0;
    dfs_set_root(id, cartesian_decomposition);
  }
  void prep_LCA() {
    MAXLEVEL = 1;
    while ((1 << MAXLEVEL) < nn) MAXLEVEL++;
    MAXLEVEL++;
    pred.assign(MAXLEVEL, vector<int>(nn, 0));
    pred[0] = parent;
    int i, j, k;
    for (i = 1; i < MAXLEVEL; i++) {
      for (j = 0; j < nn; j++) {
        if (pred[i - 1][j] != -1) pred[i][j] = pred[i - 1][pred[i - 1][j]];
      }
    }
  }
  int LCA(int a, int b) {
    int da = depth[a], db = depth[b];
    if (da > db) {
      swap(da, db);
      swap(a, b);
    }
    int i, j, k;
    for (i = MAXLEVEL - 1; i >= 0; i--) {
      if (db - (1 << i) >= da) {
        db -= (1 << i);
        b = pred[i][b];
      }
    }
    if (a == b) return a;
    for (i = MAXLEVEL - 1; i >= 0; i--) {
      if (pred[i][a] != pred[i][b]) {
        a = pred[i][a];
        b = pred[i][b];
      }
    }
    return parent[a];
  }
  int get_distance(int a, int b) {
    int c = LCA(a, b);
    int ans = depth[a] + depth[b] - 2 * depth[c];
    return ans;
  }
};
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, a, b, i, j, k, aa, bb, ans, dd;
  cin >> n >> a >> b;
  tree tr(n + 1);
  for (i = 0; i < n - 1; i++) {
    cin >> aa >> bb;
    tr.add_path(aa, bb);
  }
  vector<int> dista, distb, distleaf;
  tr.set_root(a, true);
  dista = tr.depth;
  tr.set_root(b, true);
  distb = tr.depth;
  tr.prep_LCA();
  dd = tr.get_distance(a, b);
  queue<int> q;
  distleaf.assign(n + 1, -1);
  for (i = 1; i <= n; i++) {
    if (tr.adj[i].size() == 1) {
      q.push(i);
      distleaf[i] = 0;
    }
  }
  while (!q.empty()) {
    int id = q.front();
    q.pop();
    for (auto p : tr.adj[id]) {
      if (distleaf[p] == -1) {
        distleaf[p] = distleaf[id] + 1;
        q.push(p);
      }
    }
  }
  if ((tr.adj[a].size() == 1) && (tr.adj[a][0] == b))
    ans = 1;
  else {
    ans = 0;
    for (i = 1; i <= n; i++) {
      if (dista[i] > distb[i]) continue;
      ans = max(ans, dista[i]);
    }
  }
  cout << ans << "\n";
  return 0;
}
