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 al=new Alca(li,true);
		t=s[1];
		a=s[2];
		int p=0;
		b1[t]=false;
		b1[a]=false;
		while(al.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()+(al.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 Alca{
	private List<int>[] li;
	private readonly int[] at,ix,de,l;
	private readonly int[][] g;
	private int f=0;
	public Alca(List<int>[] li,bool bo){
		int n=li.Length,z=(n<<1)-1,m=z;
		this.li=li;
		at=new int[z];
		ix=new int[n];
		de=new int[n];
		if(bo){Fu1(1,1);}
		else{
			for(int i = 1;i<n;i++) {
				if(de[i]==0){Fu1(i,1);f++;}
			}
		}
		m=(int)Log(m,2)+1;
		g=new int[m][];
		g[0]=new int[z];
		l=new int[z+1];
		for(int i=0;i<z;i++){
			g[0][i]=i;
			l[i+1]=l[i>>1]+1;
		}
		for(int i=1,k=1;i<m;i++,k<<=1){
			int p=z+1-(k<<1);
			g[i]=new int[p];
			for(int j=0;j<p;j++){g[i][j]=de[at[g[i-1][j]]]<de[at[g[i-1][j+k]]]?g[i-1][j]:g[i-1][j+k];}
		}
	}
	public int Lca(int a,int b){return Get(ix[a],ix[b]);}
	public int Di(int a,int b){
		int p=Get(ix[a],ix[b]);
		return p!=0?de[a]+de[b]-(de[p]<<1):-1;
	}
	private int Get(int a,int b){
		if(a>b){a^=b;b^=a;a^=b;}
		int p=l[b-a];
		return at[de[at[g[p][a]]]<de[at[g[p][b+1-(1<<p)]]]?g[p][a]:g[p][b+1-(1<<p)]];
	}
	private void Fu1(int a,int g){
		at[f]=a;
		de[a]=g;
		ix[a]=f;
		f++;
		for(int i=0;i<li[a].Count;i++){
			if(de[li[a][i]]==0){
				Fu1(li[a][i],g+1);
				at[f]=a;
				f++;
			}
		}
	}
}
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: 48976