#include <bits/stdc++.h>
using namespace std;
class Graph_func {
 public:
  int Vnum;
  int Enum;
  int uini, vini;
  int xstop = -1;
  int decx = -1;
  int distuv;
  vector<pair<int, int> > edgelist;
  vector<long long> edgeweight;
  vector<vector<int> > adjlist;
  vector<vector<long long> > adjlistweight;
  vector<int> adjnum;
  vector<int> xprevlist;
  vector<long long> xdist;
  vector<bool> x_visited;
  vector<int> x_prqarr;
  vector<bool> x_filled;
  void read_edge();
  void adjini();
  void visited_ini();
  void adjsort();
  vector<bool> graph_num_BFS(int BFS_ini, vector<bool> filled);
  int graph_num();
  void graph_BFS(long long BFS_ini);
  void graph_DFS(long long DFS_ini);
  void xydist_tree(int x);
  void xydist(int x);
  long long diameter();
  int dim_num(int dim);
  bool xydist_def = false;
};
void Graph_func::read_edge() {
  cin >> Vnum >> uini >> vini;
  if (true)
    Enum = Vnum - 1;
  else
    cin >> Enum;
  uini--;
  vini--;
  edgelist.resize(Enum);
  edgeweight.resize(Enum);
  adjnum.resize(Vnum);
  xdist.resize(Vnum);
  adjlist.resize(Vnum);
  xprevlist.resize(Vnum);
  if (false) adjlistweight.resize(Vnum);
  for (int(i) = 0; (i) < (Enum); (i)++) {
    if (false)
      cin >> edgelist[i].first >> edgelist[i].second >> edgeweight[i];
    else
      cin >> edgelist[i].first >> edgelist[i].second;
    if (true) {
      edgelist[i].first--;
      edgelist[i].second--;
    }
  }
  return;
}
void Graph_func::adjini() {
  for (int(i) = 0; (i) < (Vnum); (i)++) adjnum[i] = 0;
  for (int(i) = 0; (i) < (Enum); (i)++) {
    int x = edgelist[i].first;
    int y = edgelist[i].second;
    adjlist[x].push_back(y);
    if (!false) adjlist[y].push_back(x);
    if (false) {
      long long xyweight = edgeweight[i];
      adjlistweight[x].push_back(xyweight);
      if (!false) adjlistweight[y].push_back(xyweight);
    }
    adjnum[x]++;
    if (!false) adjnum[y]++;
  }
  x_visited.resize(Vnum);
  visited_ini();
  return;
}
void Graph_func::visited_ini() {
  for (int(i) = 0; (i) < (Vnum); (i)++) {
    xdist[i] = -1;
    x_visited[i] = false;
  }
  x_prqarr.resize(0);
}
void Graph_func::graph_BFS(long long BFS_ini) {
  visited_ini();
  x_prqarr.push_back(BFS_ini);
  x_visited[BFS_ini] = true;
  while (!x_prqarr.empty()) {
    int Ntmp = x_prqarr.size();
    for (int(a) = 0; (a) < (Ntmp); (a)++) {
      int x = x_prqarr[0];
      x_prqarr.erase(x_prqarr.begin());
      for (int(i) = 0; (i) < (adjnum[x]); (i)++) {
        int x_new = adjlist[x][i];
        if (!x_visited[x_new]) {
          xprevlist[x_new] = x;
          x_prqarr.push_back(x_new);
          x_visited[x_new] = true;
        }
      }
    }
  }
  return;
}
void Graph_func::graph_DFS(long long DFS_ini) {
  visited_ini();
  x_prqarr.push_back(DFS_ini);
  x_visited[DFS_ini] = true;
  while (!x_prqarr.empty()) {
    int Ntmp = x_prqarr.size();
    for (int(a) = 0; (a) < (Ntmp); (a)++) {
      int x = x_prqarr[x_prqarr.size() - 1];
      x_prqarr.pop_back();
      for (int(i) = 0; (i) < (adjnum[x]); (i)++) {
        int x_new = adjlist[x][i];
        if (!x_visited[x_new]) {
          x_prqarr.push_back(x_new);
          x_visited[x_new] = true;
        }
      }
    }
  }
  return;
}
void Graph_func::xydist_tree(int BFS_ini) {
  visited_ini();
  x_prqarr.push_back(BFS_ini);
  x_visited[BFS_ini] = true;
  while (!x_prqarr.empty()) {
    int Ntmp = x_prqarr.size();
    for (int(a) = 0; (a) < (Ntmp); (a)++) {
      int x = x_prqarr[0];
      x_prqarr.erase(x_prqarr.begin());
      for (int(i) = 0; (i) < (adjnum[x]); (i)++) {
        int x_new = adjlist[x][i];
        if (x_new == xstop) continue;
        int dist_new;
        if (false)
          dist_new = adjlistweight[x][i];
        else
          dist_new = 1;
        if (!x_visited[x_new]) {
          x_prqarr.push_back(x_new);
          xdist[x_new] = xdist[x] + dist_new;
          x_visited[x_new] = true;
        }
      }
    }
  }
  return;
}
int main(void) {
  Graph_func graph;
  long long ans = 0;
  graph.read_edge();
  graph.adjini();
  long long Vnum = graph.Vnum;
  long long Enum = graph.Enum;
  graph.graph_BFS(graph.uini);
  long long distuv = 0;
  int xtmp = graph.vini;
  vector<int> waylist(1);
  waylist[0] = xtmp;
  while (1) {
    xtmp = graph.xprevlist[xtmp];
    distuv++;
    waylist.push_back(xtmp);
    if (xtmp == graph.uini) break;
  }
  graph.xstop = waylist[distuv / 2];
  graph.decx = waylist[distuv - 1];
  graph.distuv = distuv;
  graph.visited_ini();
  graph.xydist_tree(graph.uini);
  ans++;
  if (distuv % 2 == 1) ans--;
  for (int(i) = 0; (i) < (Vnum); (i)++) {
    ans = max(graph.xdist[i], ans);
  }
  graph.xstop = graph.decx;
  graph.visited_ini();
  graph.xydist_tree(graph.uini);
  if (distuv % 2 == 1)
    for (int(i) = 0; (i) < (Vnum); (i)++) {
      ans = max(graph.xdist[i] + distuv, ans);
    }
  cout << ans << endl;
  return 0;
}
