#include <bits/stdc++.h>
using namespace std;
int n, ta, ao, ans;
vector<int> g[100010];
int dis[100010];
void bfs(int x, int p, int d) {
  if (d > dis[x]) {
    ans = max(ans, dis[x]);
    return;
  }
  for (int i = 0; i < g[x].size(); i++) {
    int &y = g[x][i];
    if (y != p) {
      bfs(y, x, d + 1);
    }
  }
  if (g[x].size() == 1) {
    ans = max(ans, dis[x] - 1);
  }
}
int main() {
  cin >> n >> ta >> ao;
  for (int i = 0; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  memset(dis, -1, sizeof(dis));
  dis[ao] = 0;
  queue<int> q;
  q.push(ao);
  while (!q.empty()) {
    int x = q.front();
    q.pop();
    for (int i = 0; i < g[x].size(); i++) {
      int &y = g[x][i];
      if (dis[y] == -1) {
        dis[y] = dis[x] + 1;
        q.push(y);
      }
    }
  }
  bfs(ta, -1, 0);
  cout << ans << endl;
  return 0;
}
