#include <bits/stdc++.h>
#define lli long long int
#define pb push_back
#define mod 1000000007
#pragma GCC optimize ("-O2")
#define mod2 998244353
#define MAXN 1000000000
#define v32 vector<int>
#define v64 vector<lli>
#define v1024 vector <vector <int>>
#define v4096 vector <vector <lli>>
#define vt vector
#define f(x, y, z) for (lli x = y; x < z; x++)
#define fd(x, y, z) for (lli x = y; x > z; x--)
#define lb lower_bound
#define ld long double
#define m64 map<lli,lli>
#define m32 map<int,int>
#define m64it map<lli,lli>::iterator
#define m32it map<int,int>::iterator
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ist insert
#define endl "\n"
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<pair<lli,int>, null_type,less<pair<lli,int>>, rb_tree_tag,tree_order_statistics_node_update> 
#define p_q priority_queue 
#define min_p_q priority_queue <int,vt <int>,greater <int>>
using namespace std;
using namespace __gnu_pbds; 
template <typename T> 
void DEBUG_ARR(vt<T> a){
	f(i,0,a.size())cout<<a[i]<<" ";
	cout<<"\n";
}
v32 Tree[100001];
int height[100001],parent[100001],depth[100001];
void dfs(int u,int p){
    parent[u]=p;
    depth[u]=depth[p]+1;
    for(auto x:Tree[u]){
        if(x==p)continue;
        dfs(x,u);
        height[u]=max(height[u],1+height[x]);
    }
}
int main() { 
    fastio;
    int n;
    cin>>n;
    int u,v;
    cin>>u>>v;
    f(i,0,n-1){
        int u,v;
        cin>>u>>v;
        Tree[u].pb(v);
        Tree[v].pb(u);
    }
    dfs(v,0);
    v32 path;
    path.pb(u);
    while(path.back()!=v){
        path.push_back(parent[path.back()]);
    }
    int ans=0;
    int pathsize=path.size();
    fd(i,pathsize-1,(pathsize-1)/2){
        int x=path[i];
        ans=max(ans,depth[x]+height[x]);
    }
    ans--;
    cout<<ans-1<<"\n";
    return 0; 	
}