#include <bits/stdc++.h>
using namespace std;
const int N = (int)2e5 + 7;
const int inf = (int)1e9 + 7;
const int mod = (int)1e9 + 7;
const long long linf = (long long)1e18 + 7;
const int dx[] = {-1, 0, 1, 0, 1, -1, -1, 1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int kx[] = {-1, 1, 2, 2, 1, -1, -2, -2};
const int ky[] = {2, 2, 1, -1, -2, -2, -1, 1};
struct dsu {
  int parent[N];
  int cont;
  void make_set(int n) {
    for (int i = 1; i <= n; i++) parent[i] = i;
    cont = n;
  }
  int find_set(int v) {
    if (v == parent[v]) return v;
    return find_set(parent[v]);
  }
  void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
      parent[b] = a;
      cont--;
    }
  }
};
vector<int> g[100007];
int vis[100007], dt[100007], da[100007];
bool leaf[100007];
int n, u, v;
void add(int u, int v) {
  g[u].push_back(v);
  g[v].push_back(u);
}
void dfs1(int x) {
  vis[x] = true;
  for (int i = 0; i < (int)g[x].size(); i++) {
    int y = g[x][i];
    if (!vis[y] && y != v) {
      dt[y] = dt[x] + 1;
      dfs1(y);
    }
  }
  if (g[x].size() == 1) leaf[x] = true;
}
void dfs2(int x) {
  vis[x] = true;
  for (int i = 0; i < (int)g[x].size(); i++) {
    int y = g[x][i];
    if (!vis[y]) {
      da[y] = da[x] + 1;
      dfs2(y);
    }
  }
  if (g[x].size() == 1 && da[x] <= dt[x]) leaf[x] = false;
}
int main() {
  memset(vis, false, sizeof(vis));
  memset(leaf, false, sizeof(leaf));
  memset(da, 0, sizeof(da));
  memset(dt, 0, sizeof(dt));
  cin >> n >> u >> v;
  for (int i = 1; i <= n - 1; i++) {
    int a, b;
    cin >> a >> b;
    add(a, b);
  }
  dfs1(u);
  memset(vis, false, sizeof(vis));
  dfs2(v);
  int dis = 0, dest = u;
  for (int i = 1; i <= n; i++) {
    if (leaf[i]) {
      if (dis < dt[i]) {
        dis = dt[i];
        dest = i;
      }
    }
  }
  cout << da[dest] - 1;
  return 0;
}
