#include <bits/stdc++.h>
using namespace std;
int n, u, v;
vector<int> G[100010];
int root;
int parent[32][100010];
int depth[100010];
void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] != p) dfs(G[v][i], v, d + 1);
  }
}
void init(int V) {
  dfs(root, -1, 0);
  for (int k = 0; k + 1 < 32; k++) {
    for (int v = 0; v < V; v++) {
      if (parent[k][v] < 0)
        parent[k + 1][v] = -1;
      else
        parent[k + 1][v] = parent[k][parent[k][v]];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int k = 0; k < 32; k++) {
    if ((depth[v] - depth[u]) >> k & 1) {
      v = parent[k][v];
    }
    if (u == v) return u;
    for (int k = 32 - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
  }
  return parent[0][u];
}
int f, dmax;
int visited[100010], v2[100010];
int dist_taka[100010], dist_aoki[100010];
void dfs2(int x, int d) {
  visited[x]++;
  dist_taka[x] = d;
  for (auto i : G[x]) {
    if (!visited[i]) {
      dfs2(i, d + 1);
    }
  }
}
void dfs3(int x, int d) {
  v2[x]++;
  dist_aoki[x] = d;
  for (auto i : G[x]) {
    if (!v2[i]) {
      dfs3(i, d + 1);
    }
  }
}
int main(void) {
  scanf("%lld %lld %lld", &n, &u, &v);
  u--, v--;
  root = v;
  for (int i = 0; i < n - 1; ++i) {
    int a, b;
    cin >> a >> b;
    a--, b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  dfs2(u, 0);
  dfs3(v, 0);
  for (int i = 0; i < n; ++i) {
    dmax = max(dmax, dist_aoki[i]);
  }
  vector<int> far;
  for (int i = 0; i < n; ++i) {
    if (dist_aoki[i] == dmax) far.push_back(i);
  }
  int m = far.size();
  int e = INT_MAX, Lca = 0, mindist = INT_MAX;
  init(n);
  for (int i = 0; i < m; ++i) {
    int x = far[i];
    if (x == u) continue;
    int y;
    y = lca(u, x);
    if (mindist > dist_taka[y]) {
      e = x, Lca = y, mindist = dist_taka[y];
    }
  }
  if (dist_aoki[Lca] <= dist_taka[Lca]) {
    cout << dist_taka[v] - 1 << endl;
  } else {
    cout << dist_aoki[e] - 1 << endl;
  }
}
