#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
const int MOD = 1e9 + 7;
vector<vector<int>> adj;
vector<int> reacha;
vector<int> reachb;
vector<int> depth;
vector<int> leaf;
vector<bool> visited;
void dfs(int v, int p) {
  if (adj[v].size() == 1) leaf.push_back(v);
  for (int i = 0; i < adj[v].size(); i++)
    if (adj[v][i] != p) {
      depth[adj[v][i]] = depth[v] + 1;
      dfs(adj[v][i], v);
    }
}
void bfs(int v, bool ab) {
  queue<pair<int, int>> q;
  q.push(make_pair(v, 0));
  while (!q.empty()) {
    visited[q.front().first] = 1;
    if (!ab)
      reacha[q.front().first] = q.front().second;
    else
      reachb[q.front().first] = q.front().second;
    for (int i = 0; i < adj[q.front().first].size(); i++)
      if (!visited[adj[q.front().first][i]])
        q.push(make_pair(adj[q.front().first][i], q.front().second + 1));
    q.pop();
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, u, v;
  cin >> n >> u >> v;
  u--;
  v--;
  adj.resize(n);
  reacha.resize(n);
  reachb.resize(n);
  depth.resize(n);
  visited.resize(n);
  depth[v] = 0;
  for (int i = 0; i < n; i++) visited[i] = 0;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  if (adj[u].size() == 1 && adj[u][0] == v) {
    cout << 0;
    return 0;
  }
  dfs(v, -1);
  bfs(u, 0);
  for (int i = 0; i < n; i++) visited[i] = 0;
  bfs(v, 1);
  int corner, furthest = 0;
  for (int i = 0; i < leaf.size(); i++)
    if (reacha[leaf[i]] < reachb[leaf[i]])
      if (reacha[leaf[i]] >= furthest) {
        furthest = reacha[leaf[i]];
        corner = leaf[i];
      }
  cout << depth[corner] - 1;
  return 0;
}
