#include <bits/stdc++.h>
using namespace std;
vector<vector<int64_t>> edges;
vector<int64_t> scores;
vector<bool> visited;
void mark(int64_t i, int64_t score) {
  scores[i] = score;
  for (int64_t next : edges[i]) {
    if (scores[next] == -1) {
      mark(next, score + 1);
    }
  }
}
int64_t max_score(int64_t i, int64_t cost) {
  visited[i] = true;
  if (scores[i] <= cost) {
    return scores[i];
  }
  int64_t score = 0;
  for (int64_t next : edges[i]) {
    if (!visited[next]) {
      score = max(score, max_score(next, cost + 1));
    }
  }
  if (!score) {
    score = scores[i];
    if (edges[i].size() <= 1) {
      return score - 1;
    }
  }
  return score;
}
void solve() {
  int64_t N, u, v;
  cin >> N >> u >> v;
  --u;
  --v;
  edges.resize(N);
  scores.resize(N, -1);
  visited.resize(N);
  for (int64_t i = 0; i < N - 1; ++i) {
    int64_t a, b;
    cin >> a >> b;
    --a;
    --b;
    edges[a].push_back(b);
    edges[b].push_back(a);
  }
  mark(v, 0);
  cout << max_score(u, 0) << endl;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}
