#include <bits/stdc++.h>
using namespace std;
const int INF = LLONG_MAX;
const int SZ = 1e5 + 5;
const int mod = 1e9 + 7;
int n, sc1, sc2;
vector<int> adj[SZ];
bool vis[SZ];
int dis[SZ];
void bfs() {
  queue<pair<int, int> > q;
  q.push({sc1, 0});
  q.push({sc2, 1});
  vis[sc2] = 1;
  while (!q.empty()) {
    int u = q.front().first;
    int st = q.front().second;
    q.pop();
    if (st == 0 && vis[u]) continue;
    for (auto v : adj[u]) {
      if (!vis[v]) {
        if (st == 0)
          dis[v] = dis[u] + 1;
        else
          vis[v] = 1;
        q.push({v, st});
      }
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int cs = 0, tc = 1, x, y, z, i, j, k, g, p, q, ans = 0, sum = 0, c = 0, t = 0;
  string s, s1, s2;
  cin >> n >> sc1 >> sc2;
  for (i = 1; i <= n - 1; i++) {
    cin >> x >> y;
    adj[x].push_back(y);
    adj[y].push_back(x);
  }
  bfs();
  ans = *max_element(dis + 1, dis + n + 1);
  cout << ans << "\n";
  return 0;
}
