import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string rstring(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T rtype(T)(){ return rstring.to!T; } alias rint = rtype!int, rlong = rtype!long, rreal = rtype!real;
T[] rtypes(T)(int n){ return n.iota.map!(i => rtype!T()).array; } alias rint = rtypes!int, rlong = rtypes!long, rreal = rtypes!real;
T[][] rtypess(T)(int n, int m){ return n.iota.map!(i => rtypes!T(m)).array; } alias rint = rtypess!int, rlong = rtypess!long, rreal = rtypess!real;
T chmin(T)(ref T x, T y){ if(x > y) x = y; return x; } T chmax(T)(ref T x, T y){ if(x < y) x = y; return x; }

// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = rint;
	Node[] nodes;
	foreach(i; 0 .. n) nodes ~= new Node(i);

	Node u = nodes[rint - 1], v = nodes[rint - 1];

	foreach(j; 0 .. n - 1){
		Node a = nodes[rint - 1], b = nodes[rint - 1];
		a.nodes ~= b, b.nodes ~= a;
	}

	u.treefy(null);
	u.setValue1;
	foreach(nd;nodes) nd.parent = null, nd.sons = [];
	v.treefy(null);
	v.setValue2;
	
	
	int ans = 0;
	foreach(nd; nodes) if(nd.value1 < nd.value2) ans.chmax(nd.value2);

	if(ans > 0) ans -= 1;

	log(nodes);
	ans.writeln;
}

class Node{
	int value1 = -1, value2 = -1;
	int id;
	Node[] nodes;
	Node[] sons;
	Node parent;
	this(int id){
		this.id = id;
	}
	void setValue1(){
		if(parent) value1 = parent.value1 + 1;
		else value1 = 0;
		foreach(son; sons) son.setValue1;
	}
	void setValue2(){
		if(parent) value2 = parent.value2 + 1;
		else value2 = 0;
		foreach(son; sons) son.setValue2;
	}
	void treefy(Node par){
		if(par) this.parent = par;
		foreach(nd; nodes){
			if(par && par.id == nd.id) continue;
			else{
				sons ~= nd;
				nd.treefy(this);
			}
		}
	}
}

