#include "bits/stdc++.h"
using namespace std;

const int MAXN = 1e5 + 5;

int n, A[2], ans;
vector<int> adj[MAXN];
int dist[2][MAXN];
bool visited[MAXN];

int main(){
	scanf("%d %d %d", &n, &A[0], &A[1]);
	for(int i = 0; i < n-1; ++i){
		int u, v;
		scanf("%d %d", &u, &v);
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	for(int j = 0; j < 2; ++j){
		memset(visited, 0, sizeof visited);
		queue<int> q;
		q.push(A[j]);
		while(!q.empty()){
			int top = q.front(); q.pop();
			if(visited[top])
				continue;
			visited[top] = true;
			for(int i : adj[top]){
				if(!visited[i]){
					dist[j][i] = dist[j][top]+1;
					q.push(i);
				}
			}
		}
	}
	for(int i = 1; i <= n; ++i){
		// printf("(%d, %d)\n", dist[0][i], dist[1][i]);
		if(dist[0][i] < dist[1][i]){
				ans = max(ans, dist[1][i]-1);
		}
	}
	printf("%d\n", ans);
}