//* Problem  : KRTICA
//* Origin   : COCI 2008-2009. Contest 1
//* Type     : Judge
//* Date     : 2009.10.10
//* Author   : alt
//* Language : C++
//* Compiler : Microsoft Visual C++ 9.0

#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <vector>
#include <algorithm>
#include "testlib.h"

using namespace std;

#define VI vector<int>

#define FOR(i,n) for (int i = 0; i < (int)(n); i++)

#define PB push_back
#define SZ(a) a.size()
#define MP make_pair
#define PII pair<int, int>
#define VI vector<int>
#define VVI vector<VI >

int n, res;

set<PII> edges;

VVI a;

int d[400000];

int q[400000], qh, qt;

void bfs(int v, int &vmax)
{
	qh = qt = 0;
	memset(d, 0, sizeof(d));
	d[v] = 1;
	q[qh++] = v;
	vmax = v;
	while (qh != qt)
	{
		v = q[qt++];
		vmax = v;
		for (VI::const_iterator it = a[v].begin(); it != a[v].end();  it++)
		{
			int u = *it;
			if (!d[u])
			{
				d[u] = d[v] + 1;
				q[qh++] = u;
			}
		}
	}
}

int main(int argc, char *argv[])
{
	registerTestlibCmd(argc, argv);

	n = inf.readInt();
	FOR(i,n-1)
	{
		int p = inf.readInt();
		int q = inf.readInt();
		if (p > q) swap(p, q);
		edges.insert(MP(p, q));
	}
	
	res = ans.readInt();
	int tres = ouf.readInt();
	if (res != tres)
		quitf(_wa, "Wrong distance: judges found %d, while contestant %d", res, tres);
	int p1 = ouf.readInt();
	int q1 = ouf.readInt();
	if (p1 > q1)
		swap(p1, q1);
	int p2 = ouf.readInt();
	int q2 = ouf.readInt();
	if (p2 > q2)
		swap(p2, q2);
	if (edges.find(MP(p1, q1)) == edges.end())
		quitf(_wa, "Removed tunnel doesn't exists %d-%d", p1, q1);
	edges.erase(edges.find(MP(p1, q1)));
	edges.insert(MP(p2, q2));
	a.assign(n + 1, VI());
	for (set<PII>::const_iterator it = edges.begin(); it != edges.end(); it++)
	{
		int p = it->first, q = it->second;
		a[p].PB(q);
		a[q].PB(p);
	}
	int vmax1;
	bfs(1, vmax1);
	for (int i = 1; i <= n; i++)
		if (!d[i])
			quitf(_wa, "Graph is disconnected: 1 not connected with %d", i);
	int vmax2, vmax3;
	bfs(vmax1, vmax2);
	bfs(vmax2, vmax3);
	if (res != d[vmax3]-1)
		quitf(_wa, "Actual diameter (%d) differents from given (%d)", d[vmax3] - 1, res);
	quitf(_ok, "OK res = %d, removed = %d, %d, added = %d, %d", res, p1, q1, p2, q2);
}
