#include <bits/stdc++.h>
using namespace std;
inline long long add(long long a, long long b) {
  return ((a % 1000000007) + (b % 1000000007)) % 1000000007;
}
inline long long mul(long long a, long long b) {
  return ((a % 1000000007) * (b % 1000000007)) % 1000000007;
}
inline long long sub(long long a, long long b) {
  return ((a % 1000000007) - (b % 1000000007) + 1000000007) % 1000000007;
}
long long depth[100000];
long long parent[100000][30];
vector<long long> adj[100000 + 1];
void dfs(int cur, int prev) {
  depth[cur] = depth[prev] + 1;
  parent[cur][0] = prev;
  for (auto it : adj[cur]) {
    if (it != prev) {
      dfs(it, cur);
    }
  }
}
long long dfs2(long long i, long long p) {
  long long ret = 0;
  for (auto it : adj[i]) {
    if (it != p) {
      ret = max(ret, dfs2(it, i) + 1);
    }
  }
  return ret;
}
void precomputeSparseMatrix(int n) {
  for (int i = 1; i < 30; i++) {
    for (int node = 1; node <= n; node++) {
      if (parent[node][i - 1] != -1)
        parent[node][i] = parent[parent[node][i - 1]][i - 1];
    }
  }
}
long long lca(long long u, long long v) {
  if (depth[v] < depth[u]) swap(u, v);
  long long diff = depth[v] - depth[u];
  for (int i = 0; i < 30; i++)
    if ((diff >> i) & 1) v = parent[v][i];
  if (u == v) return u;
  for (int i = 30 - 1; i >= 0; i--)
    if (parent[u][i] != parent[v][i]) {
      u = parent[u][i];
      v = parent[v][i];
    }
  return parent[u][0];
}
void Flash() {
  long long n, tt, aa;
  cin >> n >> tt >> aa;
  --tt, --aa;
  long long u, v;
  for (long long i = 0; i < n - 1; i++) {
    cin >> u >> v;
    --u, --v;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  dfs(0, -1);
  long long LCA = lca(tt, aa);
  long long distT = depth[tt] - depth[LCA];
  long long distA = depth[aa] - depth[LCA];
  long long ans;
  if (distA > distT) {
    ans = dfs2(tt, -1) - 1;
  } else {
    ans = dfs2(aa, -1) - 1;
  }
  cout << ans << "\n";
}
int main(int argc, char const *argv[]) {
  ios::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL);
  ;
  long long t = 1;
  for (long long i = 1; i <= t; i++) {
    Flash();
  }
  return 0;
}
