#include <math.h>
#include <vector>
#include <cstdio>
#include <iostream>

using namespace std;

const int MAXN = 1e5+5;
const int logs = (int)log2(MAXN)+5;
int parent[MAXN][logs];
int depth[MAXN];

vector<int> edges[MAXN];

bool seen[MAXN];

int N,u,v;
int n;

void calc(int c) {
  seen[c] = true;
  for (int ed : edges[c]) {
    if (seen[ed]) {continue;}
    parent[ed][0] = c;
    depth[ed] = depth[c]+1;
    calc(ed);
  }
}


/*
 * lca 1
 */

// parent[u][k] is the 2^k-th parent of u
void preprocess() {
  for (int i = 0; i < n; i++) {
    // assume parent[i][0] (the parent of i) is already filled in
    for (int j = 1; (1<<j) < n; j++) {
      parent[i][j] = -1;
    }
  }

  // fill in the parent for each power of two up to n
  for (int j = 1; (1<<j) < n; j++) {
    for (int i = 0; i < n; i++) {
      if (parent[i][j-1] != -1) {
        // the 2^j-th parent is the 2^(j-1)-th parent of the 2^(j-1)-th parent
        parent[i][j] = parent[parent[i][j-1]][j-1];
      }
    }
  }
}


/*
 * lca 2
 */

int lca (int u, int v) {
  // make sure u is deeper than v
  if (depth[u] < depth[v]) swap(u,v);
  
  // log[i] holds the largest k such that 2^k <= i
  for (int i = log2(depth[u]); i >= 0; i--) {
    // repeatedly raise u by the largest possible power of two until it is the same depth as v
    if (depth[u] - (1<<i) >= depth[v]) u = parent[u][i]; 
  }

  if (u == v) return u;

  for (int i = log2(depth[u]); i >= 0; i--)
    if (parent[u][i] != -1 && parent[u][i] != parent[v][i]) {
      // raise u and v as much as possible without having them coincide
      // this is important because we're looking for the lowest common ancestor, not just any
      u = parent[u][i];
      v = parent[v][i];
    }

  // u and v are now distinct but have the same parent, and that parent is the LCA
  return parent[u][0];
}

int from_mid() {
  int lc = lca(u,v);
  int minD = u;
  int minlc = u;
  for (int i=0;i<N;i++) {
    int tm = lca(u,i);
    int tm2 = lca(i,v);
    if (depth[i] > depth[minD] && (depth[u]-depth[tm]+depth[i]-depth[tm] < depth[v]-depth[tm2]+depth[i]-depth[tm2])) {
      minD = i;
      minlc = tm;
    }
  }
  return depth[v]-depth[lc]+depth[minD]-depth[lc]-1;
}

int from_root() {
  int lc = lca(u,v);
  int minD = u;
  for (int i=0;i<N;i++) {
    if (depth[i] < depth[minD]) {
      minD = i;
    }
  }
  return depth[v]-depth[lc]+depth[minD]-depth[lc]-1;
}

int main() {
  scanf("%d %d %d",&N,&u,&v);
  n=N;
  u--;v--;
  int A,B;
  for (int i=0;i<N-1;i++) {
    scanf("%d %d",&A,&B);
    edges[A-1].push_back(B-1);
    edges[B-1].push_back(A-1);
  }
  depth[0] = 0;
  parent[0][0] = -1;
  calc(0);
  preprocess();
  if (depth[v] <= depth[u]) {
    printf("%d\n",from_mid());
  } else {
    printf("%d\n",from_mid());
  }
  return 0;
}