#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;
 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define endl '\n'

int n,a,b;
vector<vector<int>> adj;
vector<int> vis;

int dfs1(int v = b){
    vis[v] = 1;
    if (v == a) return 0;
    int ans = 0;
    for (int c : adj[v]){
        if (!vis[c]) ans = max(ans, dfs1(c) + 1);
    }
    return ans;
}

int dfs2(int v = a){
    vis[v] = 1;
    int ans = 0;
    for (int c : adj[v]){
        if (!vis[c]) ans = max(ans, dfs2(c) + 1);
    }
    return ans;
}

void solvetask(){
    cin >> n >> a >> b;
    adj.resize(n+1);
    vis.resize(n+1);
    for (int i=1; i<n; i++){
        int u,v; cin >> u >> v;
        adj[u].push_back(v);
        adj[v].push_back(u);
    }
    cout << dfs1() + dfs2() - 1 << endl;
}
 
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int t=1; //cin >> t;
    while(t--) solvetask();
}