#include <bits/stdc++.h>
using namespace std;
inline bool isvowel(char ch) {
  ch = tolower(ch);
  return (ch == 'a' || ch == 'e' || ch == 'i' || ch == 'o' || ch == 'u');
}
bool isprime(int n) {
  if (n < 2 || (n % 2 == 0 && n != 2)) return false;
  for (int i = 3; i * i <= n; i += 2)
    if (n % i == 0) return false;
  return true;
}
const int N = 1e5 + 7;
vector<vector<int>> graph;
int used[N], dept[N], depa[N];
char q = 't';
void dfs(int v, int p, int cnt = 0) {
  used[v] = 1;
  if (q == 't' && p != v)
    dept[v] = dept[p] + 1;
  else if (p != v)
    depa[v] = depa[p] + 1;
  for (auto to : graph[v]) {
    if (!used[to]) {
      dfs(to, v, cnt + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int n, taka, aoki, i, x, y, in = -1, mx = 0;
  cin >> n >> taka >> aoki;
  graph.resize(n + 1);
  for (i = 0; i < n - 1; i++) {
    cin >> x >> y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  if (graph[taka].size() == 1 && graph[taka][0] == aoki) {
    cout << 0;
    return 0;
  }
  dfs(taka, taka);
  q = 'a';
  memset(used, 0, sizeof(used));
  dfs(aoki, aoki);
  for (i = 1; i <= n; i++) {
    if (dept[i] < depa[i]) {
      if (mx < dept[i]) {
        mx = dept[i];
        in = i;
      }
    }
  }
  if (in == -1) in = graph[graph[aoki][0]][0];
  cout << depa[in] - 1;
  return 0;
}
