#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>

// make rooted tree from tree gragh G
// INPUT: 
// N = number of nodes in G
// root_index = index of the root node
// RESULT:
// G_rooted[i] becomes the set of childs of i-th node
// par[i] becomes the index of parent of i-th node
int make_rooted_tree(std::vector<std::vector<long long int> > &G, long long int N, long long int root_index, std::vector<std::vector<long long int> > &G_rooted, std::vector<long long int> &par);

int sub_make_rooted_tree(std::vector<std::vector<long long int> > &G, long long int N, long long int root_index, std::vector<std::vector<long long int> > &G_rooted, std::vector<long long int> &par);

int make_rooted_tree(std::vector<std::vector<long long int> > &G, long long int N, long long int root_index, std::vector<std::vector<long long int> > &G_rooted, std::vector<long long int> &par){
  // initialize par and call sub_make_rooted_tree
  par[root_index] = root_index;
  sub_make_rooted_tree(G, N, root_index, G_rooted, par);

  return 0;
}

int sub_make_rooted_tree(std::vector<std::vector<long long int> > &G, long long int N, long long int root_index, std::vector<std::vector<long long int> > &G_rooted, std::vector<long long int> &par){

  for(long long int i = 0; i < G[root_index].size(); i++){
    // for all connected nodes but parent node
    if(G[root_index][i] != par[root_index]){
      par[G[root_index][i]] = root_index;
      G_rooted[root_index].push_back(G[root_index][i]);
      sub_make_rooted_tree(G, N, G[root_index][i], G_rooted, par);
    }
  }

  return 0;
}

long long int determine_rank(std::vector<std::vector<long long int> > &G_rooted, long long int index){
  if(G_rooted[index].size() == 0){
    return 0;
  }
  else{
    long long int ans = 0;
    for(long long int i = 0; i < G_rooted[index].size(); i++){
      ans = std::max(ans, determine_rank(G_rooted, G_rooted[index][i])+1);
    }
    return ans;
  }
}



int main(){

  // read problem
  long long int N, tmp1, tmp2, u, v;
  scanf("%lld%lld%lld", &N, &u, &v);
  u--;
  v--;

  std::vector<std::vector<long long int> > G(N);
  for(long long int i = 0; i < N-1; i++){
    scanf("%lld%lld", &tmp1, &tmp2);
    G[tmp1-1].push_back(tmp2-1);
    G[tmp2-1].push_back(tmp1-1);
  }

  /*std::cerr << "G:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << i << ": ";
    for(long long int j = 0; j < G[i].size(); j++){
      std::cerr << G[i][j] << " ";
    }std::cerr << std::endl;
  }std::cerr << std::endl;*/

  //std::cerr << N << " " << u << " " << v << std::endl;

  // make rooted tree
  std::vector<std::vector<long long int> > G_rooted(N);
  std::vector<long long int> par(N);

  par[v] = -1;
  make_rooted_tree(G, N, v, G_rooted, par);
  //std::cerr << "make rooted tree" << std::endl;

  /*std::cerr << "rooted tree:" << std::endl;
  for(long long int i = 0; i < N; i++){
    std::cerr << i << ": " << par[i] << ": ";
    for(long long int j = 0; j < G_rooted[i].size(); j++){
      std::cerr << G_rooted[i][j] << " ";
    }std::cerr << std::endl;
  }std::cerr << std::endl;*/

  long long int dist_uv = 0;
  tmp1 = u;
  while(tmp1 != v){
    dist_uv++;
    tmp1 = par[tmp1];
  }

  //std::cerr << "dist_uv = " << dist_uv << std::endl;
  
  long long int nup;
  if(dist_uv%2 == 1){
    tmp1 = (dist_uv-1)/2;
    for(int i = 0; i < tmp1; i++){
      u = par[u];
    }
    v = par[u];
  }
  else if(dist_uv%2 == 0){
    tmp1 = (dist_uv-2)/2;
    for(int i = 0; i < tmp1; i++){
      u = par[u];
      v = par[par[u]];
    }
  }

  std::cerr << "Answer: " << std::endl;
  //std::cerr << dist_uv << std::endl << determine_rank(G_rooted, u-1) << std::endl;
  if(dist_uv == 1 && determine_rank(G_rooted, u-1) == 0){
    std::cout << 0 << std::endl;
  }
  else if((dist_uv+2)%2 == 0){
    std::cout << tmp1 + 2 + determine_rank(G_rooted, u) -1 << std::endl;
  }
  else{
    std::cout << tmp1 + 1 + determine_rank(G_rooted, u) -1 << std::endl;
  }

  return 0;
}


Measured memory_bytes: 19584