#include <bits/stdc++.h>
using namespace std;
int n;
int u, v;
vector<int> adj[100005];
int par[100005];
int depth[100005];
int maxd[100005];
bool ao[100005];
void root(int x, int p) {
  if (par[x] != 0) return;
  par[x] = p;
  maxd[x] = depth[x];
  ao[x] = (x == v);
  for (int i = 0; i < (int)adj[x].size(); i++) {
    if (adj[x][i] == p) continue;
    depth[adj[x][i]] = depth[x] + 1;
    root(adj[x][i], x);
    maxd[x] = max(maxd[x], maxd[adj[x][i]]);
    ao[x] = (ao[x] | ao[adj[x][i]]);
  }
  return;
}
int main() {
  scanf("%d", &n);
  if (n == 2) {
    printf("0");
    return 0;
  }
  scanf("%d%d", &u, &v);
  int a, b;
  for (int i = 0; i < n - 1; i++) {
    scanf("%d%d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  root(u, 0);
  if ((int)adj[u].size() == 1) {
    int newu = adj[u][0];
    while ((int)adj[newu].size() == 2) {
      if (adj[newu][0] == par[newu])
        newu = adj[newu][1];
      else
        newu = adj[newu][0];
    }
    if (2 * depth[newu] >= depth[v]) {
      printf("%d", depth[v] - 1);
    } else {
      for (int i = 0; i < (int)adj[newu].size(); i++) {
        if (ao[adj[newu][i]]) {
          int idx;
          if (i == 0)
            idx = 1;
          else
            idx = 0;
          for (int j = 1; j < (int)adj[newu].size(); j++) {
            if (maxd[adj[newu][idx]] < maxd[adj[newu][j]]) idx = j;
          }
          if (maxd[adj[newu][idx]] > 2 * depth[newu]) {
            int ans = maxd[adj[newu][idx]];
            int diff = depth[v] - 2 * depth[newu];
            printf("%d", ans + diff - 1);
          } else {
            printf("%d", depth[v] - 1);
          }
          return 0;
        }
      }
    }
    return 0;
  }
  for (int i = 0; i < (int)adj[u].size(); i++) {
    if (ao[adj[u][i]]) {
      int idx;
      if (i == 0)
        idx = 1;
      else
        idx = 0;
      for (int j = 1; j < (int)adj[u].size(); j++) {
        if (maxd[adj[u][idx]] < maxd[adj[u][j]]) idx = j;
      }
      int ans = maxd[adj[u][idx]];
      int diff = maxd[adj[u][idx]] + depth[v];
      printf("%d", ans + diff - 1);
      return 0;
    }
  }
}
