//* Problem  : G
//* Contest  : NCPC-2009
//* Type     : Checker (TestLib)
//* Date     : 2011.01.01
//* Author   : alt
//* Language : C++
//* Compiler : GCC


#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <sstream>
#include <math.h>
#include "testlib.h"
using namespace std;

int n, res;

set<pair<int, int> > edges;

void check_edge(int a, int b, bool fAdd)
{
	if (b < a) swap(a, b);
	if (a == b)
		quitf(_wa, "Wrong edge %d-%d", a, b);
	pair<int, int> edge(a, b);
	if (fAdd)
	{
		if (edges.count(edge) == 1)
			quitf(_wa, "Edge already exists %d-%d", a, b);
		edges.insert(edge);
	}
	else
	{
		if (edges.count(edge) == 0)
			quitf(_wa, "Edge already not exists %d-%d", a, b);
		edges.erase(edge);
	}
}

vector<vector<int> > a;

queue<int> q;

#define INF (1<<20)

void bfs(int v, int *d)
{
	while (!q.empty())
		q.pop();
	for (int i = 0; i < n; i++)
		d[i] = INF;

	d[v] = 0;
	q.push(v);
	while (!q.empty())
	{
		v = q.front(); q.pop();
		for (int i = 0; i < a[v].size(); i++)
		{
			int u = a[v][i];
			if (d[u] == INF)
			{
				d[u] = d[v] + 1;
				q.push(u);
			}
		}
	}
}

int d1[3000], d2[3000];

int calc_diam()
{
	a.assign(n, vector<int>());
	for (set<pair<int, int> >::const_iterator it = edges.begin(); it != edges.end(); it++)
	{
		int p = it->first - 1;
		int q = it->second - 1;
		a[p].push_back(q);
		a[q].push_back(p);
	}

	bfs(0, d1);
	int dmax = -1, vmax = 0;
	for (int i = 0; i < n; i++)
		if (d1[i] > dmax)
		{
			dmax = d1[i];
			vmax = i;
		}

	bfs(vmax, d2);
	dmax = -1, vmax = 0;
	for (int i = 0; i < n; i++)
		if (d2[i] > dmax)
		{
			dmax = d2[i];
			vmax = i;
		}
	return dmax;
}

int main(int argc, char *argv[])
{
	registerTestlibCmd(argc, argv);
	
	// input
	n = inf.readInt();
	for (int i = 0; i < n - 1; i++)
	{
		int a = inf.readInt();
		int b = inf.readInt();
		check_edge(a, b, true);
	}

	// answer
	res = ans.readInt();

	// output
	int res_o = ouf.readInt();
	if (res != res_o)
		quitf(_wa, "Wrong answer. Expected %d, received %d", res, res_o);

	int c1 = ouf.readInt();
	int c2 = ouf.readInt();
	check_edge(c1, c2, false);

	int a1 = ouf.readInt();
	int a2 = ouf.readInt();
	check_edge(a1, a2, true);

	int res_act = calc_diam();
	if (res_act != res)
		quitf(_wa, "Wrong answer. Declared diameter - %d, actual - %d", res, res_act);

	quitf(_ok, "OK %d", res);
	return 0;
}




