#include <bits/stdc++.h>
using namespace std;
int N;
const int maxN = 100100;
vector<int> G[maxN];
int dept[maxN], depa[maxN];
void add_edge(int from, int to) {
  G[from].push_back(to);
  G[to].push_back(from);
}
void bfs(int s, int *dep) {
  queue<int> q;
  bool used[N];
  fill(used, used + N, false);
  for (int i = 0; i < N; i++) {
    dep[i] = -1;
  }
  q.push(s);
  dep[s] = 0;
  while (!q.empty()) {
    int u = q.front();
    q.pop();
    used[u] = true;
    for (int i = 0; i < G[u].size(); i++) {
      int v = G[u][i];
      if (!used[v]) {
        q.push(v);
        dep[v] = dep[u] + 1;
      }
    }
  }
}
int main() {
  int u, v;
  cin >> N;
  cin >> u >> v;
  u--;
  v--;
  for (int i = 0; i < N - 1; i++) {
    int a, b;
    cin >> a >> b;
    add_edge(--a, --b);
  }
  bfs(u, dept);
  bfs(v, depa);
  int dep = -1, x = -1;
  for (int i = 0; i < N; i++) {
    if (G[i].size() == 1) {
      if (dept[i] < depa[i]) {
        dep = max(dep, dept[i]);
        x = i;
      }
    }
  }
  cout << depa[x] - 1 << endl;
}
