#include <bits/stdc++.h>
using namespace std;
vector<long long int> bfs(vector<vector<long long int> > &g, long long int u,
                          long long int n) {
  queue<long long int> q;
  vector<long long int> d(n, -1), vis(n, 0);
  long long int c = 0;
  q.push(u);
  vis[u] = 1;
  d[u] = c;
  c++;
  while (!q.empty()) {
    long long int x = q.front();
    for (long long int i = 0; i < g[x].size(); i++) {
      if (!vis[g[x][i]]) {
        q.push(g[x][i]);
        d[g[x][i]] = c;
        vis[g[x][i]] = 1;
      }
    }
    q.pop();
    c++;
  }
  return d;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long int n, u1, v1;
  cin >> n >> u1 >> v1;
  vector<vector<long long int> > g(n);
  long long int u, v;
  for (long long int i = 0; i < n; i++) {
    cin >> u >> v;
    g[u - 1].push_back(v - 1);
    g[v - 1].push_back(u - 1);
  }
  vector<long long int> d1 = bfs(g, u1 - 1, n), d2 = bfs(g, v1 - 1, n);
  long long int ans = 0;
  for (long long int i = 0; i < n; i++) {
    if ((d1[i] != -1) && (d2[i] != -1)) {
      if (d1[i] < d2[i]) ans = max(ans, d2[i]);
    }
  }
  cout << ans - 1 << endl;
  return 0;
}
