#include <bits/stdc++.h>
using namespace std;
const int INF_INT = 2147483647;
const long long INF_LL = 9223372036854775807LL;
const unsigned long long INF_ULL = 18446744073709551615Ull;
const long long P = 92540646808111039LL;
const int Move[4][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
const int Move_[8][2] = {-1, 0, -1, -1, 0, 1, 1, 1, 1, 0, 1, -1, 0, -1, -1, -1};
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
  os << "( " << p.first << " , " << p.second << " )";
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
  for (auto ite = (v).begin(); ite != (v).end(); ++ite)
    os << (ite - v.begin()) << " : " << *ite << endl;
  return os;
}
template <typename T>
ostream& operator<<(ostream& os, const set<T>& v) {
  os << " { ";
  for (auto ite = (v).begin(); ite != (v).end(); ++ite) {
    os << *ite;
    if (ite != --v.end()) {
      os << " , ";
    }
  }
  os << " } ";
  return os;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m) {
  for (auto ite = (m).begin(); ite != (m).end(); ++ite) {
    os << ite->first << "\t\t|->\t\t" << ite->second << endl;
  }
  return os;
}
long long n, u, v;
vector<long long> T[100005];
bool searched[100005];
bool foundmark[100005];
long long dist[100005];
int main() {
  cin >> n >> u >> v;
  memset(searched, 0, sizeof(searched));
  memset(foundmark, 0, sizeof(foundmark));
  memset(dist, 0, sizeof(dist));
  for (long long i = 1; i <= (n - 1); i++) {
    long long a, b;
    cin >> a >> b;
    T[a].push_back(b);
    T[b].push_back(a);
  }
  for (long long i = 1; i <= (n); i++)
    if (0) {
    };
  if (0) {
  };
  queue<long long> bfs;
  bool marked = false;
  bfs.push(v);
  searched[v] = true;
  long long maxdist = 0;
  while (!bfs.empty()) {
    if (0) {
    };
    long long id = bfs.front();
    bfs.pop();
    if (0) {
    };
    for (auto ite = (T[id]).begin(); ite != (T[id]).end(); ++ite) {
      if (0) {
      };
      if (0) {
      };
      if (searched[*ite]) continue;
      if (0) {
      };
      if (marked && !foundmark[id]) break;
      if (0) {
      };
      if (marked) {
        foundmark[*ite] = true;
      }
      if (0) {
      };
      searched[*ite] = true;
      dist[*ite] = dist[id] + 1;
      if (0) {
      };
      if (*ite == u) {
        if (0) {
        };
        marked = true;
        foundmark[*ite] = true;
      }
      if (marked) {
        (maxdist) = max(maxdist, dist[*ite]);
      }
      bfs.push(*ite);
    }
  }
  cout << (maxdist - 1) << endl;
  return 0;
}
