#include <bits/stdc++.h>
using namespace std;
struct AdjListNode {
  long long dest;
  long long weight;
  struct AdjListNode* next;
};
struct AdjList {
  struct AdjListNode* head;
};
struct Graph {
  long long V;
  struct AdjList* array;
};
struct AdjListNode* newAdjListNode(long long dest, long long weight) {
  struct AdjListNode* newNode =
      (struct AdjListNode*)malloc(sizeof(struct AdjListNode));
  newNode->dest = dest;
  newNode->weight = weight;
  newNode->next = NULL;
  return newNode;
}
struct Graph* createGraph(long long V) {
  struct Graph* graph = (struct Graph*)malloc(sizeof(struct Graph));
  graph->V = V;
  graph->array = (struct AdjList*)malloc(V * sizeof(struct AdjList));
  for (long long i = 0; i < V; ++i) graph->array[i].head = NULL;
  return graph;
}
void addEdge(struct Graph* graph, long long src, long long dest,
             long long weight) {
  struct AdjListNode* newNode = newAdjListNode(dest, weight);
  newNode->next = graph->array[src].head;
  graph->array[src].head = newNode;
  newNode = newAdjListNode(src, weight);
  newNode->next = graph->array[dest].head;
  graph->array[dest].head = newNode;
}
struct MinHeapNode {
  long long v;
  long long dist;
};
struct MinHeap {
  long long size;
  long long capacity;
  long long* pos;
  struct MinHeapNode** array;
};
struct MinHeapNode* newMinHeapNode(long long v, long long dist) {
  struct MinHeapNode* minHeapNode =
      (struct MinHeapNode*)malloc(sizeof(struct MinHeapNode));
  minHeapNode->v = v;
  minHeapNode->dist = dist;
  return minHeapNode;
}
struct MinHeap* createMinHeap(long long capacity) {
  struct MinHeap* minHeap = (struct MinHeap*)malloc(sizeof(struct MinHeap));
  minHeap->pos = (long long*)malloc(capacity * sizeof(long long));
  minHeap->size = 0;
  minHeap->capacity = capacity;
  minHeap->array =
      (struct MinHeapNode**)malloc(capacity * sizeof(struct MinHeapNode*));
  return minHeap;
}
void swapMinHeapNode(struct MinHeapNode** a, struct MinHeapNode** b) {
  struct MinHeapNode* t = *a;
  *a = *b;
  *b = t;
}
void minHeapify(struct MinHeap* minHeap, long long idx) {
  long long smallest, left, right;
  smallest = idx;
  left = 2 * idx + 1;
  right = 2 * idx + 2;
  if (left < minHeap->size &&
      minHeap->array[left]->dist < minHeap->array[smallest]->dist)
    smallest = left;
  if (right < minHeap->size &&
      minHeap->array[right]->dist < minHeap->array[smallest]->dist)
    smallest = right;
  if (smallest != idx) {
    MinHeapNode* smallestNode = minHeap->array[smallest];
    MinHeapNode* idxNode = minHeap->array[idx];
    minHeap->pos[smallestNode->v] = idx;
    minHeap->pos[idxNode->v] = smallest;
    swapMinHeapNode(&minHeap->array[smallest], &minHeap->array[idx]);
    minHeapify(minHeap, smallest);
  }
}
long long isEmpty(struct MinHeap* minHeap) { return minHeap->size == 0; }
struct MinHeapNode* extractMin(struct MinHeap* minHeap) {
  if (isEmpty(minHeap)) return NULL;
  struct MinHeapNode* root = minHeap->array[0];
  struct MinHeapNode* lastNode = minHeap->array[minHeap->size - 1];
  minHeap->array[0] = lastNode;
  minHeap->pos[root->v] = minHeap->size - 1;
  minHeap->pos[lastNode->v] = 0;
  --minHeap->size;
  minHeapify(minHeap, 0);
  return root;
}
void decreaseKey(struct MinHeap* minHeap, long long v, long long dist) {
  long long i = minHeap->pos[v];
  minHeap->array[i]->dist = dist;
  while (i && minHeap->array[i]->dist < minHeap->array[(i - 1) / 2]->dist) {
    minHeap->pos[minHeap->array[i]->v] = (i - 1) / 2;
    minHeap->pos[minHeap->array[(i - 1) / 2]->v] = i;
    swapMinHeapNode(&minHeap->array[i], &minHeap->array[(i - 1) / 2]);
    i = (i - 1) / 2;
  }
}
bool isInMinHeap(struct MinHeap* minHeap, long long v) {
  if (minHeap->pos[v] < minHeap->size) return true;
  return false;
}
vector<long long> dijkstra(struct Graph* graph, long long src) {
  long long V = graph->V;
  long long dist[V];
  struct MinHeap* minHeap = createMinHeap(V);
  for (long long v = 0; v < V; ++v) {
    dist[v] = 99999999999999;
    minHeap->array[v] = newMinHeapNode(v, dist[v]);
    minHeap->pos[v] = v;
  }
  minHeap->array[src] = newMinHeapNode(src, dist[src]);
  minHeap->pos[src] = src;
  dist[src] = 0;
  decreaseKey(minHeap, src, dist[src]);
  minHeap->size = V;
  while (!isEmpty(minHeap)) {
    struct MinHeapNode* minHeapNode = extractMin(minHeap);
    long long u = minHeapNode->v;
    struct AdjListNode* pCrawl = graph->array[u].head;
    while (pCrawl != NULL) {
      long long v = pCrawl->dest;
      if (isInMinHeap(minHeap, v) && dist[u] != 99999999999999 &&
          pCrawl->weight + dist[u] < dist[v]) {
        dist[v] = dist[u] + pCrawl->weight;
        decreaseKey(minHeap, v, dist[v]);
      }
      pCrawl = pCrawl->next;
    }
  }
  vector<long long> v;
  for (long long i = 0; i < V; i++) {
    v.push_back(dist[i]);
  }
  return v;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long i, j, k, n, u, v, a, b, ans = 0, r;
  cin >> n >> a >> b;
  struct Graph* graph = createGraph(n + 1);
  for (i = 0; i < n - 1; i++) {
    cin >> u >> v;
    addEdge(graph, u, v, 1);
  }
  vector<long long> v1, v2;
  v1 = dijkstra(graph, a);
  v2 = dijkstra(graph, b);
  for (i = 1; i <= n; i++) {
    if (v2[i] > v1[i]) {
      r = v1[i] + (v2[i] - v1[i]) / 2;
      ans = max(ans, r);
    }
  }
  cout << ans << "\n";
  return 0;
}
