#include <bits/stdc++.h>
using namespace std;
int Set(int N, int pos) { return N = N | (1 << pos); }
int reset(int N, int pos) { return N = N & ~(1 << pos); }
bool check(int N, int pos) { return (bool)(N & (1 << pos)); }
inline int addmod(long long int x, long long int y) {
  return (x % 1000000007 + y % 1000000007) % 1000000007;
}
inline int submod(long long int x, long long int y) {
  return (x % 1000000007 - y % 1000000007 + 1000000007) % 1000000007;
}
inline int mulmod(long long int x, long long int y) {
  return (x % 1000000007 * y % 1000000007) % 1000000007;
}
inline int nextSubMask(int i, int mask) { return (i - 1) & mask; }
template <typename T>
void we_r_done(T mssg) {
  cout << mssg;
  exit(0);
}
const int N = 1e5 + 6;
vector<int> tree[N];
int du[N], dv[N];
void dfsu(int x, int p) {
  for (int u : tree[x]) {
    if (p != u) {
      du[u] = du[x] + 1;
      dfsu(u, x);
    }
  }
}
void dfsv(int x, int p) {
  for (int u : tree[x]) {
    if (p != u) {
      dv[u] = dv[x] + 1;
      dfsv(u, x);
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  ;
  int n, u, v;
  while (cin >> n) {
    cin >> u >> v;
    for (int i = 1; i <= n; i++) tree[i].clear();
    bool bad = false;
    for (int i = 1; i < n; i++) {
      int x, y;
      cin >> x >> y;
      tree[x].push_back(y);
      tree[y].push_back(x);
    }
    du[u] = dv[v] = 0;
    dfsu(u, u);
    dfsv(v, v);
    int ans = 0;
    for (int i = 1; i <= n; i++) {
      ans = max(ans, dv[i] - 1);
    }
    cout << ans << endl;
  }
  return 0;
}
