#include <bits/stdc++.h>
using namespace std;
string vow = "aeiou";
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};
const int dx[] = {-1, 0, 0, 1};
const int dy[] = {0, -1, 1, 0};
const long double pie = 3.14159265358979;
const long long mod = 1e9 + 7;
vector<vector<int> > g;
vector<int> level;
void dfs(int node, int parent = -1) {
  if (parent != -1) level[node] = level[parent] + 1;
  for (auto i : g[node]) {
    if (i == parent) continue;
    ;
    dfs(i, node);
  }
}
int max_level = -1;
void dfs2(int node, int parent = -1) {
  max_level = max(max_level, level[node]);
  for (auto i : g[node]) {
    if (i == parent) continue;
    ;
    dfs2(i, node);
  }
}
void solve(int test_case) {
  int n, node, root;
  cin >> n >> node >> root;
  node--;
  root--;
  g.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  level.resize(n);
  dfs(root);
  int dis = level[node];
  if (dis % 2 == 0) dis--;
  dis >>= 1;
  int ans = dis;
  int tak_current = level[node] - dis;
  int oki_current = dis;
  dfs2(tak_current);
  dis = max_level - tak_current;
  ans += dis;
  oki_current += dis;
  tak_current = max_level;
  int c = 0;
  while (oki_current != tak_current) {
    if (c == 0)
      tak_current--;
    else
      tak_current++;
    if (tak_current == oki_current) break;
    oki_current++;
    ans++;
    c ^= 1;
  }
  cout << ans;
  cout << "\n";
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  for (int i = 0; i < t; i++) solve(i);
  return 0;
}
