#include <bits/stdc++.h>
using namespace std;
int N, u, v;
const int N_MAX = 100000;
int A[100000], B[100000];
vector<int> G[100000];
bool used[100000];
bool leaf[100000];
int root;
const int N_LOG_MAX = 25;
int parent[N_LOG_MAX][N_MAX];
int depth[N_MAX];
void dfs(int v, int p, int d) {
  parent[0][v] = p;
  depth[v] = d;
  for (int i = 0; i < G[v].size(); i++) {
    if (G[v][i] != p) dfs(G[v][i], v, d + 1);
  }
}
void init(int V) {
  dfs(root, -1, 0);
  for (int i = 0; i < N_LOG_MAX - 1; i++) {
    for (int v = 0; v < V; v++) {
      if (parent[i][v] < 0)
        parent[i + 1][v] = -1;
      else
        parent[i + 1][v] = parent[i][parent[i][v]];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int i = 0; i < N_LOG_MAX; i++) {
    if ((depth[v] - depth[u]) >> i & 1) {
      v = parent[i][v];
    }
  }
  if (u == v) return u;
  for (int i = N_LOG_MAX - 1; i >= 0; i--) {
    if (parent[i][u] != parent[i][v]) {
      u = parent[i][u];
      v = parent[i][v];
    }
  }
  return parent[0][u];
}
void dfs(int v, int d) {
  used[v] = true;
  depth[v] = d;
  for (int i = 0; i < G[v].size(); i++) {
    if (!used[G[v][i]]) {
      dfs(G[v][i], d + 1);
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(10) << fixed;
  cin >> N >> u >> v;
  u--;
  v--;
  for (int i = 0; i < N - 1; i++) {
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
    G[A[i]].push_back(B[i]);
    G[B[i]].push_back(A[i]);
  }
  for (int i = 0; i < N; i++) {
    if (G[i].size() == 1) leaf[i] = true;
  }
  root = v;
  init(N);
  int ans;
  int cur = -1;
  for (int i = 0; i < N; i++) {
    if (leaf[i]) {
      int la = lca(u, i);
      if (depth[la] < depth[u] - depth[la]) continue;
      if (depth[la] == depth[u] - depth[la]) {
        if (cur < depth[la]) {
          cur = depth[la];
        }
        continue;
      }
      if (i == u) {
        int len;
        if (depth[i] % 2 == 0) {
          len = depth[i] - 1;
        } else {
          len = depth[i] - 1;
        }
        if (cur < len) cur = len;
        continue;
      }
      int len = depth[u] + depth[i] - 2 * depth[la];
      if (len % 2 != depth[i] % 2) {
        if (cur < depth[i] - 1) {
          cur = depth[i] - 1;
        }
      } else {
        if (cur < depth[i]) {
          cur = depth[i];
        }
      }
    }
  }
  cout << cur << endl;
}
