#include <bits/stdc++.h>
using namespace std;
inline void prep() {
  cin.tie(0);
  cin.sync_with_stdio(0);
};
const double pi = acos(-1.);
long long mod = 1000000007;
long long mymod(long long num) {
  if (num < 0 && !(num % mod == 0)) {
    if (mod == 1) {
      return 0;
    }
    return mod - abs(num) % mod;
  } else {
    return num % mod;
  }
}
double eps = .000000001;
vector<int> graph[100001];
int dists[100001];
int distsv[100001];
int deps[100001];
void dfs(int node, int par, int dist) {
  dists[node] = dist;
  for (int i : graph[node]) {
    if (i == par) {
      continue;
    }
    dfs(i, node, dist + 1);
  }
}
int dfs2(int node, int par, int dist) {
  distsv[node] = dist;
  int maxdep = 0;
  for (int i : graph[node]) {
    if (i == par) {
      continue;
    }
    maxdep = max(maxdep, dfs2(i, node, dist + 1));
  }
  deps[node] = maxdep;
  return maxdep + 1;
}
int main() {
  prep();
  int n, u, v;
  cin >> n >> u >> v;
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    graph[a].push_back(b);
    graph[b].push_back(a);
  }
  dfs(u, -1, 0);
  dfs2(v, -1, 0);
  int maxest = 0;
  for (int i = 1; i <= n; i++) {
    if (dists[i] <= distsv[i]) {
      continue;
    }
    int adist = distsv[i] + deps[i];
    maxest = max(maxest, distsv[i] + deps[i] - 1);
  }
  cout << maxest;
  return 0;
}
