#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define long long long 

typedef trie<string,null_type,trie_string_access_traits<>,pat_trie_tag,trie_prefix_search_node_update> pref_trie;
typedef tree<long int,null_type,less<long int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef cc_hash_table<long int,long int, hash<long int>, equal_to<long int>, direct_mask_range_hashing<long int>, 
hash_standard_resize_policy<hash_exponential_size_policy<>, hash_load_check_resize_trigger<true>, true>> ht;


void DFS(long int idx, vector<vector<long int>> &g, unordered_set<long int> &visited, vector<long int> &distance){
	visited.insert(idx);
	for(auto ele : g[idx]){
		if(visited.find(ele) == visited.end()){
			DFS(ele,g,visited,distance);
			distance[ele] = distance[idx] + 1;
		}
	}
}

int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
 
   long int n,u,v;
   cin>>n>>u>>v;

   vector<vector<long int>> g(n);
   for(long int i = 1; i < n; i++){
   	long int x,y;
   	cin>>x>>y;
   	g[x-1].push_back(y-1);
   	g[y-1].push_back(x-1);
   }

   vector<long int> distance1(n),distance2(n);
   unordered_set<long int> visited;

   for(auto ele : g[u-1]){
   		visited.insert(u-1);
   		if(visited.find(ele) == visited.end()){
   			distance1[ele] = 1;
   			DFS(ele,g,visited,distance1);
   		}
   }

   visited.clear();
   for(auto ele : g[v-1]){
   		visited.insert(v-1);
   		if(visited.find(ele) == visited.end()){
   			distance2[ele] = 1;
   			DFS(ele,g,visited,distance2);
   		}
   }

   long int ans = 0;

   // for(auto ele : distance2)
   // 	cout<<ele<<" ";
   // cout<<endl;

   for(long int i = 0; i < n; i++){
   	if(distance1[i] < distance2[i]){
   		ans = max(ans,distance2[i] - 1);
   	}
   }

   cout<<ans;

   return 0;
}