#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;


class Graph{
  long int v;
  unordered_map<long int,unordered_set<long int>> adj;

public:
    Graph(long int n){
      v = n + 1;
    }

    void addEdge(long int u, long int v){
      adj[u].insert(v);
      adj[v].insert(u);
    }

    vector<long int> BFS(long int u){
      vector<long int> distance(v,LONG_MAX);
      distance[u] = 0;
      unordered_set<long int> visited;

      visited.insert(u);
      queue<long int> q;
      q.push(u);

      while(!q.empty()){
        auto e = q.front();
        q.pop();

        for(auto ele : adj[e]){
          if(visited.find(ele) == visited.end()){
            distance[ele] = distance[e] + 1;
            q.push(ele);
            visited.insert(ele);
          }
        }
      }
      for(auto &ele : distance)
        if(ele == LONG_MAX)
          ele = -1;
      return distance;
    }
};

int main(){
   IOS;
 //    #ifndef ONLINE_JUDGE
 //        freopen("in.txt",  "r",  stdin);
 //        freopen("out.txt", "w", stdout);
 //    #endif
   


   long int n,m,k;
   cin>>n>>m>>k;

   Graph g(n);
   for(long int i = 1; i < n; i++){
    long int u,v;
    cin>>u>>v;
    g.addEdge(u,v);
   }


   vector<long int> a = g.BFS(m);
   vector<long int> b = g.BFS(k);

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


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

   long int ans = 0;
   for(long int i = 1; i <= n; i++)
    if(a[i] == b[i-1]){
      cout<<a[i];
      return 0;
    }

    cout<<ans;
   return 0;
}