#include <bits/stdc++.h>
#pragma GCC optimize("O2")
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline long long add(long long a, long long b, long long m) {
  return (((a % m + b % m) % m + m) % m);
}
inline long long mul(long long a, long long b, long long m) {
  return (((a % m * b % m) % m + m) % m);
}
const double EPS = 1e-6;
const long long MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p) {
  out << '[' << p.first << ", " << p.second << ']';
  return out;
}
template <template <typename, typename...> class ContainerType,
          typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c) {
  cout << "{ ";
  for (const auto &v : c) cout << v << ' ';
  cout << '}' << '\n';
}
const int N = 1e5 + 5;
struct lca {
  vector<int> ndist;
  vector<vector<int> > up;
  int lgn;
  void dfs(int ii, int pp, vector<vector<int> > &g) {
    for (auto jj : g[ii])
      if (jj != pp) {
        ndist[jj] = 1 + ndist[ii];
        up[jj][0] = ii;
        dfs(jj, ii, g);
      }
  }
  lca(int n, int src, vector<vector<int> > &g) {
    lgn = ceil(1.0 * log2(n + 1));
    ndist.assign(n + 1, 0);
    up.assign(n + 1, vector<int>(lgn, -1));
    ndist[src] = 0;
    up[src][0] = src;
    dfs(src, 0, g);
    for (int i = 1; i < lgn; i++)
      for (int j = 1; j < n + 1; j++) up[j][i] = up[up[j][i - 1]][i - 1];
  }
  int getLCA(int a, int b) {
    if (ndist[a] > ndist[b]) swap(a, b);
    int diff = ndist[b] - ndist[a];
    for (int i = 0; i < lgn; i++)
      if (diff & (1 << i)) b = up[b][i];
    if (a == b) return a;
    for (int i = lgn - 1; i >= 0; i--)
      if (up[a][i] != up[b][i]) a = up[a][i], b = up[b][i];
    return up[a][0];
  }
  int getDist(int a, int b) {
    int ans = ndist[a] + ndist[b] - 2 * ndist[getLCA(a, b)];
    return ans;
  }
};
void dfs(int ii, int pp, vector<vector<int> > &g, int h, int &mx) {
  mx = max(h, mx);
  for (auto jj : g[ii])
    if (jj != pp) dfs(jj, ii, g, h + 1, mx);
  return;
}
void solve() {
  int n, t, a;
  cin >> n >> t >> a;
  vector<vector<int> > g(n + 1, vector<int>());
  int u, v;
  for (int i = 0; i < n - 1; i++) {
    cin >> u >> v;
    g[u].push_back(v);
    g[v].push_back(u);
  }
  lca L(n, a, g);
  int l = L.getLCA(t, a);
  long long ans = L.getDist(l, a);
  int mx = -1;
  dfs(l, L.up[l][0], g, 0, mx);
  ans += (mx - 1);
  cout << ans << '\n';
  return;
}
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  clock_t start, stop;
  int t = 1;
  for (int tc = 1; tc < t + 1; tc++) solve();
  return 0;
}
