#include <bits/stdc++.h>
using namespace std;
const int BUF = 100005;
int nNode, s, t;
vector<int> adj[BUF];
void read() {
  for (int i = 0; i < BUF; ++i) adj[i].clear();
  cin >> nNode >> s >> t;
  --s;
  --t;
  for (int i = 0; i < nNode - 1; ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
}
void bfs(int bgn, int cost[BUF]) {
  queue<int> Q;
  cost[bgn] = 0;
  Q.push(bgn);
  while (!Q.empty()) {
    int cur = Q.front();
    Q.pop();
    for (int i = 0; i < adj[cur].size(); ++i) {
      int nex = adj[cur][i];
      if (cost[nex] == -1) {
        cost[nex] = cost[cur] + 1;
        Q.push(nex);
      }
    }
  }
}
void work() {
  int costS[BUF];
  int costT[BUF];
  memset(costS, -1, sizeof(costS));
  memset(costT, -1, sizeof(costT));
  bfs(s, costS);
  bfs(t, costT);
  int ans = 0;
  for (int i = 0; i < nNode; ++i) {
    if (costS[i] < costT[i]) continue;
    if (costS[i] % 2 == costT[i] % 2) {
      if (adj[i].size() == 1)
        ans = max(ans, costS[i] - 2);
      else
        ans = max(ans, costS[i]);
    } else {
      ans = max(ans, costS[i] - 1);
    }
  }
  cout << ans << endl;
}
int main() {
  read();
  work();
  return 0;
}
