using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using static System.Math;
using System.Numerics;
static class Program{
	const int mod=(int)1e9+7;
	static List<int>[] li;
	static bool[] b,b1,b2;
	static int[] h,s;
	static int t,a;
	static void Main(){
		Sc sc=new Sc();
		s=sc.Ia;
		int n=s[0],m=s[0]-1;
		li=new List<int>[n+1];
		b=new bool[n+1];
		b1=new bool[n+1];
		b2=new bool[n+1];
		h=new int[n+1];
		for(int i=1;i<=n;i++){li[i]=new List<int>();}
		for(int i=0;i<m;i++){
			var e=sc.Ia;
			li[e[0]].Add(e[1]);
			li[e[1]].Add(e[0]);
		}
		Fu1(s[1]);
		b=new bool[n+1];
		var da=new Dlca<int>(li,true);
		t=s[1];
		a=s[2];
		int p=0;
		b1[t]=false;
		b1[a]=false;
		while(da.Di(t,a)>2){
			p++;
			for(int i=0;i<li[t].Count;i++){
				if(b1[li[t][i]]){
					b1[li[t][i]]=false;
					t=li[t][i];
					break;
				}
			}
			for(int i=0;i<li[a].Count;i++){
				if(b1[li[a][i]]){
					b1[li[a][i]]=false;
					a=li[a][i];
					break;
				}
			}
		}
		b=new bool[n+1];
		Fu(t,0);
		Console.WriteLine("{0}",p+h.Max()+(da.Di(t,a)==2?1:0));
	}
	static bool Fu1(int a){
		b[a]=true;
		if(a==s[2]){b1[a]=true;}
		for(int i=0;i<li[a].Count;i++){
			if(!b[li[a][i]]){
				if(Fu1(li[a][i])){b1[a]=true;}
			}
		}
		return b1[a];
	}
	static void Fu(int c,int g){
		b[c]=true;
		if(b1[c]||a==c){return;}
		h[c]=g;
		for(int i=0;i<li[c].Count;i++){
			if(!b[li[c][i]]){Fu(li[c][i],g+1);}
		}
	}
}
public class Dlca<T>{
	private bool[] b;
	private int[][] h;
	private int[] de;
	private int o;
	private List<T>[] li;
	public Dlca(List<T>[] li,bool bo){
		this.li=li;
		int n=li.Length;
		o=(int)Log(n-1,2)+1;
		de=new int[n];
		de[0]=-1;
		h=new int[o][];
		b=new bool[n];
		h[0]=new int[n];
		if(bo){
			if(li.GetType()==typeof(List<int>[])){Fd1(1,0);}
			else{Fd2(1,0);}
		}
		else{
			if(li.GetType()==typeof(List<int>[])){for(int i=1;i<n;i++){if(!b[i]){Fd1(i,0);}}}
			else{for(int i=1;i<n;i++){if(!b[i]){Fd2(i,0);}}}
		}
		for(int i=1;i<o;i++){
			h[i]=new int[n];
			for(int j=1;j<n;j++){h[i][j]=h[i-1][h[i-1][j]];}
		}
	}
	private void Fd1(int a,int f){
		b[a]=true;
		de[a]=f;
		for(int i=0;i<li[a].Count;i++){
			int j=(int)(object)li[a][i];
			if(!b[j]){h[0][j]=a;Fd1(j,f+1);}
		}
	}
	private void Fd2(int a,int f){
		b[a]=true;
		de[a]=f;
		for(int i=0;i<li[a].Count;i++){
			int j=((Tuple<int,int>)(object)li[a][i]).Item1;
			if(!b[j]){h[0][j]=a;Fd2(j,f+((Tuple<int,int>)(object)li[a][i]).Item2);}
		}
	}
	public int Lca(int a,int b){
		if(de[a]>de[b]){int c=a;a=b;b=c;}
		for(int i=o-1;de[a]!=de[b];i--){if(de[h[i][b]]>=de[a]){b=h[i][b];}}
		if(a==b){return a;}
		for(int i=o-1;i>=0;i--){if(h[i][a]!=h[i][b]){a=h[i][a];b=h[i][b];}}
		return h[0][a];
	}
	public int Di(int a,int b){
		int l=Lca(a,b);
		return l!=0?de[a]+de[b]-(de[l]<<1):int.MinValue;
	}
}

public class Sc{
	public int I{get{return int.Parse(Console.ReadLine());}}
	public long L{get{return long.Parse(Console.ReadLine());}}
	public double D{get{return double.Parse(Console.ReadLine());}}
	public string S{get{return Console.ReadLine();}}
	public int[] Ia{get{return Array.ConvertAll(Console.ReadLine().Split(),int.Parse);}}
	public long[] La{get{return Array.ConvertAll(Console.ReadLine().Split(),long.Parse);}}
	public double[] Da{get{return Array.ConvertAll(Console.ReadLine().Split(),double.Parse);}}
	public string[] Sa{get{return Console.ReadLine().Split();}}
	public object[] Oa{get{return Console.ReadLine().Split();}}
	public int[] Ia2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),int.Parse);}}
	public int[] Ia3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),int.Parse);}
	public int[] Ia3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),int.Parse);}
	public long[] La2{get{return Array.ConvertAll(("0 "+Console.ReadLine()+" 0").Split(),long.Parse);}}
	public long[] La3(int a){return Array.ConvertAll((a.ToString()+" "+Console.ReadLine()).Split(),long.Parse);}
	public long[] La3(bool a,int b,bool c,int d){return Array.ConvertAll(((a?b.ToString()+" ":"")+Console.ReadLine()+(c?" "+d.ToString():"")).Split(),long.Parse);}
	public T[] Arr<T>(int n,Func<T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f();}return a;}
	public T[] Arr<T>(int n,Func<int,T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i);}return a;}
	public T[] Arr<T>(int n,Func<string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(Console.ReadLine().Split());}return a;}
	public T[] Arr<T>(int n,Func<int,string[],T> f){var a=new T[n];for(int i=0;i<n;i++){a[i]=f(i,Console.ReadLine().Split());}return a;}
}

Measured memory_bytes: 43840