#include <bits/stdc++.h>
using namespace std;
using P = pair<long, long>;
const int mod = 1000000007;
struct edge {
  int to;
  int cost;
};
const int MAX_V = 100005;
vector<edge> G[MAX_V];
class LCA {
 public:
  long V, logV;
  vector<long> depth, len;
  vector<vector<long> > parent;
  LCA(long V) {
    this->V = V;
    logV = 0;
    while (V > (1LL << logV)) logV++;
    this->depth = vector<long>(V);
    this->len = vector<long>(V);
    this->parent = vector<vector<long> >(logV, vector<long>(V));
  }
  void init(long v, long par, long d, long l) {
    depth[v] = d;
    parent[0][v] = par;
    len[v] = l;
    for (int i = 0; i < (int)G[v].size(); i++) {
      long w = G[v][i].to;
      long lc = G[v][i].cost;
      if (w == par) continue;
      init(w, v, d + 1, lc + l);
    }
  }
  void build() {
    for (int k = 0; k + 1 < logV; k++) {
      for (int v = 0; v < V; v++) {
        if (parent[k][v] < 0)
          parent[k + 1][v] = -1;
        else
          parent[k + 1][v] = parent[k][parent[k][v]];
      }
    }
  }
  long query(long u, long v) {
    if (depth[u] > depth[v]) swap(u, v);
    for (int k = 0; k < logV; k++) {
      if ((depth[v] - depth[u]) >> k & 1) v = parent[k][v];
    }
    if (u == v) return u;
    for (int k = logV - 1; k >= 0; k--) {
      if (parent[k][u] != parent[k][v]) {
        u = parent[k][u];
        v = parent[k][v];
      }
    }
    return parent[0][u];
  }
};
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  int u, v;
  cin >> u >> v;
  u--;
  v--;
  for (int i = int(0); i < int(n - 1); i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    G[a].push_back({b, 1});
    G[b].push_back({a, 1});
  }
  LCA lca(n);
  lca.init(0, -1, 0, 0);
  lca.build();
  int z = lca.query(u, v);
  if (lca.len[u] <= lca.len[v]) {
    cout << (lca.len[u] + lca.len[v] - 2 * lca.len[z]) / 2 << endl;
  } else {
    long mx = 0;
    for (int i = int(0); i < int(n); i++) {
      int z = lca.query(i, v);
      mx = max(mx, lca.len[i] + lca.len[v] - 2 * lca.len[z]);
    }
    cout << mx - 1 << endl;
  }
}
