Each New Year Timofey and his friends cut down a tree of n vertices and bring it home. After that they paint all the n its vertices, so that the i-th vertex gets color c_{i}.

Now it's time for Timofey birthday, and his mother asked him to remove the tree. Timofey removes the tree in the following way: he takes some vertex in hands, while all the other vertices move down so that the tree becomes rooted at the chosen vertex. After that Timofey brings the tree to a trash can.

Timofey doesn't like it when many colors are mixing together. A subtree annoys him if there are vertices of different color in it. Timofey wants to find a vertex which he should take in hands so that there are no subtrees that annoy him. He doesn't consider the whole tree as a subtree since he can't see the color of the root vertex.

A subtree of some vertex is a subgraph containing that vertex and all its descendants.

Your task is to determine if there is a vertex, taking which in hands Timofey wouldn't be annoyed.


-----Input-----

The first line contains single integer n (2 ≤ n ≤ 10^5) — the number of vertices in the tree.

Each of the next n - 1 lines contains two integers u and v (1 ≤ u, v ≤ n, u ≠ v), denoting there is an edge between vertices u and v. It is guaranteed that the given graph is a tree.

The next line contains n integers c_1, c_2, ..., c_{n} (1 ≤ c_{i} ≤ 10^5), denoting the colors of the vertices.


-----Output-----

Print "NO" in a single line, if Timofey can't take the tree in such a way that it doesn't annoy him.

Otherwise print "YES" in the first line. In the second line print the index of the vertex which Timofey should take in hands. If there are multiple answers, print any of them.


-----Examples-----
Input
4
1 2
2 3
3 4
1 2 1 1

Output
YES
2
Input
3
1 2
2 3
1 2 3

Output
YES
2
Input
4
1 2
2 3
3 4
1 2 1 2

Output
NO

Source: codeforces | Difficulty: MEDIUM_HARD
Tags: Graph algorithms

Graph traversal

Implementation

Tree algorithms

Dynamic programming

Spanning trees


Solutions:
n = int(input())
b = []
U = []
V = []
w = 0
f = 1
for i in range(n):
	b.append(0)
for i in range(1, n):
	(uu, vv) = map(int, input().split())
	U.append(uu)
	V.append(vv)
c = [int(x) for x in input().split()]
for i in zip(U, V):
	if c[i[0] - 1] != c[i[1] - 1]:
		b[i[0] - 1] += 1
		b[i[1] - 1] += 1
		w += 1
for i in range(n):
	if b[i] == w:
		print('YES')
		print(i + 1)
		f = 0
		break
if f:
	print('NO')


import math
from collections import defaultdict
import os
import sys
from io import BytesIO, IOBase
ii = lambda : int(input())
lmii = lambda : list(map(int, input().split()))
slmii = lambda : sorted(map(int, input().split()))
li = lambda : list(input())
mii = lambda : map(int, input().split())
msi = lambda : map(str, input().split())

def gcd(a, b):
	if b == 0:
		return a
	return gcd(b, a % b)

def lcm(a, b):
	return a * b // gcd(a, b)

def main():
	n = ii()
	adj = defaultdict(list)
	for i in range(n - 1):
		(x, y) = mii()
		adj[x].append(y)
		adj[y].append(x)
	col = lmii()
	ans = []
	if len(set(col)) == 1:
		print('YES')
		print(1)
	else:
		for i in adj:
			for j in adj[i]:
				if col[i - 1] != col[j - 1]:
					ans.append([i, j])
		if len(ans) == 2:
			print('YES')
			print(ans[0][0])
		else:
			s = {ans[0][1], ans[0][0]}
			for i in ans:
				s.intersection_update({i[0], i[1]})
			if len(s) == 1:
				print('YES')
				print(s.pop())
			else:
				print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
graph = [[] for i in range(n)]
edges = []
for i in range(n - 1):
	(a, b) = map(int, input().split())
	graph[a - 1].append(b - 1)
	graph[b - 1].append(a - 1)
	edges.append((a - 1, b - 1))
colors = list(map(int, input().split()))

def check(root):
	mk = {}
	mk[root] = 1

	def dfs(v, value):
		res = True
		mk[v] = 1
		for w in graph[v]:
			if w not in mk:
				if colors[w] != value:
					return False
				res &= dfs(w, value)
		return res
	for x in graph[root]:
		if not dfs(x, colors[x]):
			return False
	return True
for (a, b) in edges:
	if colors[a] != colors[b]:
		if check(a):
			print('YES')
			print(a + 1)
		elif check(b):
			print('YES')
			print(b + 1)
		else:
			print('NO')
		exit()
print('YES')
print(1)


def ri():
	return map(int, input().split())
n = int(input())
e = []
for i in range(n - 1):
	(a, b) = ri()
	a -= 1
	b -= 1
	e.append([a, b])
c = list(ri())
ed = []
for ee in e:
	if c[ee[0]] != c[ee[1]]:
		ed.append(ee)
if len(ed) == 0:
	print('YES')
	print(1)
	exit()
cand = ed[0]
not0 = 0
not1 = 0
for ee in ed:
	if cand[0] != ee[0] and cand[0] != ee[1]:
		not0 = 1
		break
for ee in ed:
	if cand[1] != ee[0] and cand[1] != ee[1]:
		not1 = 1
		break
if not0 == 0:
	print('YES')
	print(cand[0] + 1)
elif not1 == 0:
	print('YES')
	print(cand[1] + 1)
else:
	print('NO')


n = int(input())
es = []
rs = []
for i in range(n - 1):
	es.append(list(map(int, input().split())))
vs = list(map(int, input().split()))
for i in es:
	if vs[i[0] - 1] != vs[i[1] - 1]:
		rs.append(i)
if rs == []:
	print('YES')
	print(1)
	exit(0)
for r1 in rs[0]:
	for i in rs:
		if r1 != i[0] and r1 != i[1]:
			break
	else:
		print('YES')
		print(r1)
		exit(0)
print('NO')


n = int(input())
e = []
v = []
for i in range(n - 1):
	e.append(list(map(int, input().split())))
c = [-1] + list(map(int, input().split()))
for i in e:
	if c[i[0]] != c[i[1]]:
		v.append(i)
if not v:
	print('YES')
	print(1)
else:
	s = set(v[0])
	list(map(lambda x: s.intersection_update(set(x)), v))
	if s:
		print('YES')
		print(list(s)[0])
	else:
		print('NO')


import sys
input = sys.stdin.readline
MOD = 1000000007
MOD2 = 998244353
ii = lambda : int(input().strip('\n'))
si = lambda : input().strip('\n')
dgl = lambda : list(map(int, input().strip('\n')))
f = lambda : map(int, input().strip('\n').split())
il = lambda : list(map(int, input().strip('\n').split()))
ls = lambda : list(input().strip('\n'))
lsi = lambda : [int(i) for i in ls()]
let = 'abcdefghijklmnopqrstuvwxyz'
for _ in range(1):
	n = ii()
	edges = [il() for i in range(n - 1)]
	clr = [0] + il()
	deg = [0] * (n + 1)
	tot = 0
	for i in edges:
		if clr[i[0]] != clr[i[1]]:
			deg[i[0]] += 1
			deg[i[1]] += 1
			tot += 1
	for i in range(1, n + 1):
		if deg[i] == tot:
			print('YES\n' + str(i))
			return
	print('NO')


from sys import stdin
input = lambda : stdin.readline().strip()
from math import ceil, sqrt, factorial, gcd
from collections import deque
n = int(input())
a = []
b = []
for i in range(n - 1):
	(x, y) = map(int, input().split())
	a.append(x)
	b.append(y)
l = list(map(int, input().split()))
ans = []
for i in range(n - 1):
	if l[a[i] - 1] != l[b[i] - 1]:
		if len(ans) == 0:
			ans = [a[i], b[i]]
		elif a[i] in ans and b[i] in ans:
			print('NO')
			return
		elif a[i] in ans:
			ans = [a[i]]
		elif b[i] in ans:
			ans = [b[i]]
		else:
			print('NO')
			return
print('YES')
if ans:
	print(ans[0])
else:
	print(1)


n = int(input())
count = [0] * (n + 1)
arr = []
for i in range(n - 1):
	(u, v) = map(int, input().split())
	arr.append([u, v])
c = list(map(int, input().split()))
countd = 0
for (i, (u, v)) in enumerate(arr):
	if c[u - 1] != c[v - 1]:
		countd += 1
		count[u] += 1
		count[v] += 1
maxi = 0
index = -1
for i in range(1, n + 1):
	if count[i] > maxi:
		maxi = count[i]
		index = i
if countd == 0:
	print('YES')
	print(1)
elif maxi == countd:
	print('YES')
	print(index)
else:
	print('NO')


def process(e, c):
	different = set([])
	root = None
	for (a, b) in e:
		if c[a - 1] != c[b - 1]:
			if len(different) == 0:
				different.add(a)
				different.add(b)
			elif len(different) == 2:
				(x, y) = different
				if x == a or x == b:
					different = set([x])
					root = x
				elif y == a or y == b:
					different = set([y])
					root = y
				else:
					return ['NO', None]
			elif root != a and root != b:
				return ['NO', None]
	if len(different) == 2:
		(x, y) = different
		return ['YES', x]
	elif root is None:
		return ['YES', 1]
	return ['YES', root]
n = int(input())
e = []
for i in range(n - 1):
	(a, b) = [int(x) for x in input().split()]
	e.append([a, b])
c = [int(x) for x in input().split()]
(a1, a2) = process(e, c)
print(a1)
if a1 == 'YES':
	print(a2)


n = int(input())
edges = [tuple(map(int, input().split())) for i in range(n - 1)]
colours = input().split()
possible_roots = []
for edge in edges:
	(one, two) = edge
	if colours[one - 1] != colours[two - 1]:
		possible_roots.append(edge)
if len(possible_roots) == 0:
	print('YES')
	print(1)
	exit()
(one, two) = possible_roots[0]
is_one_root = False
is_two_root = False
for edge in possible_roots[1:]:
	if one in edge:
		is_one_root = True
	elif two in edge:
		is_two_root = True
	else:
		print('NO')
		exit()
if is_one_root and is_two_root:
	print('NO')
	exit()
print('YES')
if is_one_root:
	print(one)
else:
	print(two)


n = int(input())
a = []
b = []
for i in range(n - 1):
	(x, y) = list(map(int, input().split()))
	a.append(x)
	b.append(y)
colors = list(map(int, input().split()))
lehet = []
for i in range(n - 1):
	if colors[a[i] - 1] != colors[b[i] - 1]:
		if len(lehet) == 0:
			lehet += [a[i], b[i]]
		elif a[i] in lehet and b[i] in lehet:
			print('NO')
			return
		elif a[i] in lehet:
			lehet = [a[i]]
		elif b[i] in lehet:
			lehet = [b[i]]
		else:
			print('NO')
			return
print('YES')
if len(lehet) == 0:
	lehet = [1]
print(lehet[0])


import sys
sys.setrecursionlimit(10 ** 5 * 2)

def debug(x, table):
	for (name, val) in table.items():
		if x is val:
			print('DEBUG:{} -> {}'.format(name, val), file=sys.stderr)
			return None

def same_col(vx, u, adj, col):
	res = True
	for child in adj[vx]:
		if child == u:
			continue
		if col[child] != col[vx]:
			return False
		else:
			res = res and same_col(child, vx, adj, col)
	return res

def solve():
	n = int(input())
	adj = [[] for i in range(n)]
	edges = [] * n
	for i in range(n - 1):
		(u, v) = map(int, sys.stdin.readline().split())
		(u, v) = (u - 1, v - 1)
		edges.append([u, v])
		adj[u].append(v)
		adj[v].append(u)
	col = [int(i) for i in input().split()]
	for (u, v) in edges:
		if col[u] != col[v]:
			break
	for vx in adj[u]:
		if not same_col(vx, u, adj, col):
			break
	else:
		print('YES')
		print(u + 1)
		return None
	for vx in adj[v]:
		if not same_col(vx, v, adj, col):
			break
	else:
		print('YES')
		print(v + 1)
		return None
	print('NO')
solve()


R = lambda : map(int, input().split())
n = int(input())
es = [list(R()) for i in range(n - 1)]
ns = [0] + list(R())
cnt = [0] * (n + 1)
ecnt = 0
for e in es:
	if ns[e[0]] != ns[e[1]]:
		cnt[e[0]] += 1
		cnt[e[1]] += 1
		ecnt += 1
ncnt = sum((1 if x else 0 for x in cnt))
maxnode = max(((x, i) for (i, x) in enumerate(cnt)))[-1]
if not ecnt or ecnt == ncnt - 1 == max(cnt):
	print('YES')
	print(maxnode)
else:
	print('NO')


from sys import stdin

def main():
	n = int(input())
	l = stdin.read().splitlines()
	cc = list(map(int, l.pop().split()))
	g = [[] for _ in range(n)]
	for s in l:
		(u, v) = map(int, s.split())
		g[u - 1].append(v - 1)
		g[v - 1].append(u - 1)
	(avail, st) = ([True] * n, [0])

	def dfs(a):
		(stack, avail[a], color, other) = ([a], False, cc[a], [])
		while stack:
			a = stack.pop()
			if cc[a] != color:
				other.append(a)
			else:
				for b in g[a]:
					if avail[b]:
						avail[b] = False
						stack.append(b)
		return other
	for (head, vv) in enumerate(g):
		if len(vv) == 1:
			(heads, r) = (dfs(head), True)
			break
	if heads:
		if len(heads) == 1:
			head = heads[0]
			for u in g[head]:
				if avail[u]:
					heads = dfs(u)
					r &= not heads
		else:
			(l, heads) = (heads, set(g[heads[0]]))
			for u in l:
				avail[u] = True
				heads &= set(g[u])
			if len(heads) == 1:
				head = heads.pop()
				for u in g[head]:
					if avail[u]:
						heads = dfs(u)
						r &= not heads
			else:
				r = False
	print(f'YES\n{head + 1}' if r else 'NO')
main()


def main():
	n = int(input())
	edges = []
	for _ in range(n - 1):
		(u, v) = list(map(int, input().split()))
		u -= 1
		v -= 1
		edges.append((u, v))
	colors = list(map(int, input().split()))
	suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]]
	if len(suspect) == 0:
		print('YES')
		print(1)
	else:
		cands = set(suspect[0])
		for (u, v) in suspect:
			cands &= set([u, v])
		if len(cands) == 0:
			print('NO')
		else:
			print('YES')
			e = list(cands)[0]
			print(e + 1)
main()


n = int(input())
ip = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	ip[a].append(b)
	ip[b].append(a)
col = list(map(int, input().split()))
cs = [0 for i in range(n)]
for i in range(n):
	count = 0
	for j in ip[i]:
		if col[j] != col[i]:
			count += 1
	cs[i] = count
count = 0
c1 = 0
for i in range(n):
	if cs[i] == 0:
		continue
	elif cs[i] == 1:
		c1 += 1
		ans1 = i + 1
	else:
		count += 1
		ans = i + 1
if count == 0:
	if c1 == 0:
		print('YES')
		print(1)
	elif c1 == 2:
		print('YES')
		print(ans1)
	else:
		print('NO')
elif count == 1:
	if c1 <= len(ip[ans - 1]):
		print('YES')
		print(ans)
	else:
		print('NO')
else:
	print('NO')


n = int(input())
graph = dict()
for i in range(1, n + 1):
	graph[i] = []
diff = []
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
color = list(map(int, input().split()))
flag = 0
for i in range(1, n + 1):
	if graph[i] != []:
		for j in graph[i]:
			if color[i - 1] != color[j - 1]:
				diff.append(i)
				diff.append(j)
				flag = 1
				break
		if flag == 1:
			break

def dfs(graph, node, col, parentnode):
	if color[node - 1] != col:
		return -1
	if graph[node] != []:
		for i in graph[node]:
			if i != parentnode:
				f1 = dfs(graph, i, col, node)
				if f1 == -1:
					return -1
	return 1
if flag == 0:
	print('YES')
	print(n)
else:
	f = 1
	for i in graph[diff[0]]:
		f = dfs(graph, i, color[i - 1], diff[0])
		if f == -1:
			break
	if f != -1:
		print('YES')
		print(diff[0])
	if f == -1:
		f2 = 1
		for i in graph[diff[1]]:
			f2 = dfs(graph, i, color[i - 1], diff[1])
			if f2 == -1:
				break
		if f2 == -1:
			print('NO')
		else:
			print('YES')
			print(diff[1])


import collections
import sys

def read_ints():
	return [int(x) for x in sys.stdin.readline().strip().split()]

def main():
	N = read_ints()[0]
	edges = []
	vx_to_neighbor_colors = collections.defaultdict(set)
	for _ in range(N - 1):
		(u, v) = read_ints()
		u -= 1
		v -= 1
		edges.append((u, v))
	colors = read_ints()
	vx_to_cnt = collections.Counter()
	e_cnt = 0
	for e in edges:
		if colors[e[0]] == colors[e[1]]:
			continue
		vx_to_cnt[e[0]] += 1
		vx_to_cnt[e[1]] += 1
		e_cnt += 1
	if e_cnt == 0:
		return 1
	if e_cnt == 1:
		return 1 + list(vx_to_cnt.keys())[0]
	root = None
	for (vx, cnt) in list(vx_to_cnt.items()):
		if cnt == e_cnt:
			if root is not None:
				return None
			root = 1 + vx
		elif cnt != 1:
			return None
	return root

def __starting_point():
	root = main()
	if root is not None:
		print(f'YES\n{root}')
	else:
		print('NO')
__starting_point()


n = int(input())
arr = []
brr = []
for i in range(n - 1):
	(u, v) = list(map(int, input().split()))
	arr.append(u)
	brr.append(v)
color = list(map(int, input().split()))
ans = []
for i in range(n - 1):
	if color[arr[i] - 1] != color[brr[i] - 1]:
		if ans == []:
			ans += [arr[i], brr[i]]
		elif arr[i] in ans and brr[i] in ans:
			print('NO')
			return
		elif arr[i] in ans:
			ans = [arr[i]]
		elif brr[i] in ans:
			ans = [brr[i]]
		else:
			print('NO')
			return
print('YES')
if len(ans) == 0:
	ans.append(1)
print(ans[0])


import math
graph = []
colors = []

def dfs(u, p, color) -> bool:
	if color != colors[u]:
		return False
	for v in graph[u]:
		if v == p:
			continue
		if not dfs(v, u, color):
			return False
	return True

def check(u):
	for v in graph[u]:
		if not dfs(v, u, colors[v]):
			return False
	return True

def main():
	n = int(input())
	for _ in range(n):
		graph.append([])
	for i in range(n - 1):
		(u, v) = map(lambda x: int(x) - 1, input().split())
		graph[u].append(v)
		graph[v].append(u)
	global colors
	colors += list(map(int, input().split()))
	for u in range(n):
		for v in graph[u]:
			if colors[u] != colors[v]:
				if check(u):
					print('YES')
					print(u + 1)
					exit(0)
				elif check(v):
					print('YES')
					print(v + 1)
					exit(0)
				else:
					print('NO')
					exit(0)
	print('YES')
	print(1)
main()


n = int(input())
g = [[] for i in range(n)]
for i in range(n - 1):
	(a, b) = map(int, input().split())
	a -= 1
	b -= 1
	g[a].append(b)
	g[b].append(a)
col = list(map(int, input().split()))
s = [set() for i in range(n)]
count = [0 for i in range(n)]
for i in range(n):
	for j in range(len(g[i])):
		if col[g[i][j]] != col[i]:
			s[i].add(col[g[i][j]])
			count[i] += 1
t = 0
for i in range(n):
	if len(s[i]) > len(s[t]):
		t = i
	elif len(s[i]) == len(s[t]) and count[i] > count[t]:
		t = i
flag = True
for i in range(n):
	for j in range(len(g[i])):
		if col[g[i][j]] != col[i]:
			if i != t and g[i][j] != t:
				flag = False
if flag:
	print('YES')
	print(t + 1)
else:
	print('NO')


import sys, os, io
import math, bisect, operator
(inf, mod) = (float('inf'), 10 ** 9 + 7)
from itertools import groupby, accumulate
from heapq import heapify, heappop, heappush
from collections import deque, Counter, defaultdict
input = iter(sys.stdin.buffer.read().decode().splitlines()).__next__
Neo = lambda : list(map(int, input().split()))
(test,) = Neo()
n = test
edges = []
for _ in range(n - 1):
	(u, v) = Neo()
	u -= 1
	v -= 1
	edges.append((u, v))
colors = Neo()
suspect = [(u, v) for (u, v) in edges if colors[u] != colors[v]]
if len(suspect) == 0:
	print('YES')
	print(1)
else:
	cands = set(suspect[0])
	for (u, v) in suspect:
		cands &= set([u, v])
	if len(cands) == 0:
		print('NO')
	else:
		print('YES')
		e = list(cands)[0]
		print(e + 1)


class Node:

	def __init__(self, number, color, adjacency_set):
		self.number = number
		self.color = color
		self.adjacency_set = adjacency_set

def main():
	n = int(input())
	tree = []
	for i in range(n):
		tree.append(Node(i + 1, 0, set()))
	for i in range(n - 1):
		I = input().split(' ')
		a = int(I[0])
		b = int(I[1])
		tree[a - 1].adjacency_set.add(tree[b - 1])
		tree[b - 1].adjacency_set.add(tree[a - 1])
	I = input().split(' ')
	for i in range(n):
		tree[i].color = int(I[i])
	edges = set()
	for node in tree:
		for adjacent_node in node.adjacency_set:
			if node.color != adjacent_node.color:
				edges.add(frozenset([node, adjacent_node]))
	if len(edges) == 0:
		print('YES')
		print(1)
		return
	if len(edges) == 1:
		print('YES')
		only_set = edges.pop()
		print(list(only_set)[0].number)
		return
	intersection = edges.pop()
	for edge in edges:
		intersection &= edge
		if len(intersection) == 0:
			print('NO')
			return
	print('YES')
	print(list(intersection)[0].number)
main()


n = int(input())
g = [[] for _ in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	u -= 1
	v -= 1
	g[u].append(v)
	g[v].append(u)
c = list(map(int, input().split()))
dif = [0 for i in range(n)]
cnt = 0
for v in range(n):
	dif[v] = 0
	for u in g[v]:
		if c[u] != c[v]:
			dif[v] += 1
	cnt += dif[v] > 0
ans = -1
for v in range(n):
	if dif[v] + 1 >= cnt:
		ans = v + 1
if ans >= 0:
	print('YES\n%d' % ans)
else:
	print('NO')


import sys

class UnionFind:

	def __init__(self, sz):
		self.__ranks = [1] * sz
		self.__sizes = [1] * sz
		self.__parents = [i for i in range(sz)]

	def find_parent(self, x):
		if x == self.__parents[x]:
			return x
		else:
			self.__parents[x] = self.find_parent(self.__parents[x])
			return self.__parents[x]

	def same(self, x, y):
		return self.find_parent(x) == self.find_parent(y)

	def unite(self, x, y):
		px = self.find_parent(x)
		py = self.find_parent(y)
		if px == py:
			return
		if self.__ranks[px] > self.__ranks[py]:
			self.__parents[py] = px
			self.__sizes[px] += self.__sizes[py]
		else:
			self.__parents[px] = py
			self.__sizes[py] += self.__sizes[px]
			if self.__ranks[px] == self.__ranks[py]:
				self.__ranks[py] += 1

	def size(self, n):
		return self.__sizes[n]

def main():
	n = int(input())
	edge = {}
	for i in range(n - 1):
		(u, v) = list(map(int, sys.stdin.readline().split()))
		if u not in edge:
			edge[u] = []
		if v not in edge:
			edge[v] = []
		edge[u].append(v)
		edge[v].append(u)
	colors = [-1] * (n + 1)
	for (i, c) in enumerate(map(int, sys.stdin.readline().split())):
		colors[i + 1] = c
	uf = UnionFind(n + 1)
	for u in list(edge.keys()):
		for v in edge[u]:
			if colors[u] == colors[v]:
				uf.unite(u, v)
	tree = set()
	for v in range(1, n + 1):
		tree.add(uf.find_parent(v))
	target_v = -1
	ok = False
	for u in range(1, n + 1):
		cnt = set()
		for v in edge[u]:
			cnt.add(uf.find_parent(v))
		if len(cnt) == len(tree) - (1 if uf.size(uf.find_parent(u)) == 1 else 0):
			ok = True
			target_v = u
			break
	if ok:
		print('YES')
		print(target_v)
	else:
		print('NO')

def __starting_point():
	main()
__starting_point()


n = int(input())
edges = list((list(map(int, input().split())) for _ in range(n - 1)))
colors = list(map(int, input().split()))
edge_cnt = 0
pnt_cnt = {0: 0}
for (a, b) in edges:
	a -= 1
	b -= 1
	if colors[a] != colors[b]:
		edge_cnt += 1
		pnt_cnt[a] = pnt_cnt.get(a, 0) + 1
		pnt_cnt[b] = pnt_cnt.get(b, 0) + 1
for (k, v) in list(pnt_cnt.items()):
	if v == edge_cnt:
		print('YES')
		print(k + 1)
		break
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
from collections import Counter

def find(z, p):
	a = []
	while p[z] != z:
		a.append(z)
		z = p[z]
	for i in a:
		p[i] = z
	return z

def union(x, y, p, s):
	(x, y) = (find(x, p), find(y, p))
	if x != y:
		if s[x] > s[y]:
			p[y] = p[x]
			s[x] += s[y]
		else:
			p[x] = p[y]
			s[y] += s[x]

def main():
	n = int(input())
	edges = [list(map(int, input().split())) for _ in range(n - 1)]
	tree = [[] for _ in range(n + 1)]
	for (x, y) in edges:
		tree[x].append(y)
		tree[y].append(x)
	c = [0] + list(map(int, input().split()))
	p = [i for i in range(n + 1)]
	s = [1] * (n + 1)
	for i in edges:
		if c[i[0]] == c[i[1]]:
			union(i[0], i[1], p, s)
	a = Counter()
	for i in range(1, n + 1):
		a[find(i, p)] += 1
	ans = 0
	for i in range(1, n + 1):
		b = set()
		for j in tree[i]:
			b.add(find(j, p))
		if len(b) + (a[i] == 1) == len(a):
			ans = i
			break
	if ans:
		print('YES')
		print(ans)
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

@bootstrap
def dfs(v, c, d, k, p):
	if o[v - 1] != c:
		k[0] = 0
	for i in d[v]:
		if i != p:
			yield dfs(i, c, d, k, v)
	yield
n = int(input())
l = []
d = {}
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	if u in d:
		d[u].append(v)
	else:
		d[u] = [v]
	if v in d:
		d[v].append(u)
	else:
		d[v] = [u]
	l.append((u, v))
o = list(map(int, input().split()))
f = 0
for i in l:
	e1 = i[0]
	e2 = i[1]
	if o[e1 - 1] != o[e2 - 1]:
		k1 = [1]
		for z in d[e1]:
			dfs(z, o[z - 1], d, k1, e1)
		if k1[0] == 1:
			print('YES')
			print(e1)
			exit()
		k2 = [1]
		for z in d[e2]:
			dfs(z, o[z - 1], d, k2, e2)
		if k2[0] == 1:
			print('YES')
			print(e2)
			exit()
		print('NO')
		exit()
print('YES')
print(1)


n = int(input())
e = []
c = [-1]
diff = []
for i in range(n - 1):
	e.append(list(map(int, input().split(' '))))
for i in map(int, input().split(' ')):
	c.append(i)
for i in range(n - 1):
	if c[e[i][0]] != c[e[i][1]]:
		diff.append(e[i])
if not diff:
	print('YES')
	print(e[0][0])
else:
	s = set(diff[0])
	for d in diff:
		s.intersection_update(d)
	if s:
		print('YES')
		print(list(s)[0])
	else:
		print('NO')


from __future__ import print_function
import sys
from collections import *
from heapq import *
from functools import *
import re
from itertools import *
INF = float('inf')
NINF = float('-inf')
try:
	input = raw_input
except:
	pass

def read_string():
	return input()

def read_string_line():
	return [x for x in input().split(' ')]

def read_int_line():
	return [int(x) for x in input().split(' ')]

def read_int():
	return int(input())
n = read_int()
adjs = [[] for _ in range(n)]
UC = -1
MC = -2
for _ in range(n - 1):
	(a, b) = read_int_line()
	adjs[a - 1].append(b - 1)
	adjs[b - 1].append(a - 1)
colors = read_int_line()
ed = {}

def dfs(frm, to):
	if (frm, to) in ed:
		return ed[frm, to]
	ct = colors[to]
	for nto in adjs[to]:
		if nto == frm:
			continue
		c = dfs(to, nto)
		if ct != c:
			ed[frm, to] = MC
			return MC
	ed[frm, to] = ct
	return ct
if True:
	cans = set(range(n))
	for frm in range(n):
		for to in adjs[frm]:
			if colors[frm] != colors[to]:
				cans &= set([frm, to])
	if not cans:
		print('NO')
	else:
		print('YES')
		print(list(cans)[0] + 1)
else:
	for frm in range(n):
		for to in adjs[frm]:
			dfs(frm, to)
			dfs(to, frm)
	for i in range(n):
		for to in adjs[i]:
			if ed[i, to] == MC:
				break
		else:
			print('YES')
			print('%d' % (i + 1))
			break
	else:
		print('NO')


n = int(input())
edges = []
for i in range(n - 1):
	edges.append(list(map(int, input().split())))
colors = [0] + list(map(int, input().split()))
tops = []
for e in edges:
	if colors[e[0]] != colors[e[1]]:
		tops.append(e)
if not tops:
	print('YES')
	print(1)
else:
	s = set(tops[0])
	list(map(lambda t: s.intersection_update(set(t)), tops))
	if s:
		print('YES')
		print(list(s)[0])
	else:
		print('NO')


import os
import sys
from io import BytesIO, IOBase
from types import GeneratorType
from collections import defaultdict
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
sys.setrecursionlimit(2 * 10 ** 5)

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

@bootstrap
def dfs(u, p, v):
	if v != col[u - 1]:
		global f1
		global f2
		f1 = 0
		f2 = 0
	if p == 0:
		for j in adj[u]:
			if j != p:
				yield dfs(j, u, col[j - 1])
	else:
		for j in adj[u]:
			if j != p:
				yield dfs(j, u, col[u - 1])
	yield
n = int(input())
adj = [[] for i in range(n + 1)]
res = []
for j in range(n - 1):
	(u, v) = map(int, input().split())
	res.append([u, v])
	adj[u].append(v)
	adj[v].append(u)
col = list(map(int, input().split()))
(v1, v2) = (0, 0)
for j in res:
	if col[j[0] - 1] != col[j[1] - 1]:
		(v1, v2) = (j[0], j[1])
if v1 == 0 and v2 == 0:
	print('YES')
	print(1)
else:
	f1 = 1
	f2 = 1
	dfs(v1, 0, col[v1 - 1])
	if f1 == 1:
		print('YES')
		print(v1)
	else:
		f2 = 1
		dfs(v2, 0, col[v2 - 1])
		if f2 == 1:
			print('YES')
			print(v2)
		else:
			print('NO')


read = lambda : map(int, input().split())
n = int(input())
ed = []
for i in range(n - 1):
	(u, v) = read()
	ed.append((u, v))
c = [0] + list(read())
cnt = [0] * (n + 1)
for (u, v) in ed:
	if c[u] != c[v]:
		cnt[u] += 1
		cnt[v] += 1
all = sum(cnt) // 2
for i in range(1, n + 1):
	if cnt[i] == all:
		print('YES')
		print(i)
		exit()
print('NO')


import math, sys, bisect, heapq, os
from collections import defaultdict, Counter, deque
from itertools import groupby, accumulate
from functools import lru_cache
int1 = lambda x: int(x) - 1

def input():
	return sys.stdin.readline().rstrip('\r\n')
aj = lambda : list(map(int, input().split()))

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def Y(c):
	print(['NO', 'YES'][c])

def y(c):
	print(['no', 'yes'][c])

def Yy(c):
	print(['No', 'Yes'][c])

def solve():
	G = defaultdict(list)

	def addEdge(a, b):
		G[a].append(b)
		G[b].append(a)

	def dfs(node, p):
		d = deque()
		d.append(node)
		vis[node] = True
		while d:
			x = d.pop()
			for i in G.get(x, []):
				if not vis[i] and i != p:
					vis[i] = True
					d.append(i)
					if C[node - 1] != C[i - 1]:
						return False
		return True
	(n,) = aj()
	m = n - 1
	vis = [False] * (n + 1)
	edges = set()
	for i in range(m):
		(u, v) = aj()
		addEdge(u, v)
		edges.add((u, v))
	C = aj()
	if len(set(C)) == 1:
		Y(1)
		print(1)
		exit(0)
	u = v = None
	for (i, j) in edges:
		if C[i - 1] != C[j - 1]:
			u = i
			v = j
			break
	vis = [False] * (n + 1)
	if all([dfs(i, u) for i in G.get(u, [])]):
		Y(1)
		print(u)
		exit(0)
	vis = [False] * (n + 1)
	if all([dfs(i, v) for i in G.get(v, [])]):
		Y(1)
		print(v)
		exit(0)
	Y(0)
try:
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')
except:
	pass
solve()


import sys, os, io

def rs():
	return sys.stdin.readline().rstrip()

def ri():
	return int(sys.stdin.readline())

def ria():
	return list(map(int, sys.stdin.readline().split()))

def ws(s):
	sys.stdout.write(s + '\n')

def wi(n):
	sys.stdout.write(str(n) + '\n')

def wia(a):
	sys.stdout.write(' '.join([str(x) for x in a]) + '\n')
import math, datetime, functools, itertools, operator, bisect, fractions, statistics
from collections import deque, defaultdict, OrderedDict, Counter
from fractions import Fraction
from decimal import Decimal
from sys import stdout
from heapq import heappush, heappop, heapify, _heapify_max, _heappop_max, nsmallest, nlargest
INF = 999999999999999999999999
alphabets = 'abcdefghijklmnopqrstuvwxyz'

class SortedList:

	def __init__(self, iterable=[], _load=200):
		values = sorted(iterable)
		self._len = _len = len(values)
		self._load = _load
		self._lists = _lists = [values[i:i + _load] for i in range(0, _len, _load)]
		self._list_lens = [len(_list) for _list in _lists]
		self._mins = [_list[0] for _list in _lists]
		self._fen_tree = []
		self._rebuild = True

	def _fen_build(self):
		self._fen_tree[:] = self._list_lens
		_fen_tree = self._fen_tree
		for i in range(len(_fen_tree)):
			if i | i + 1 < len(_fen_tree):
				_fen_tree[i | i + 1] += _fen_tree[i]
		self._rebuild = False

	def _fen_update(self, index, value):
		if not self._rebuild:
			_fen_tree = self._fen_tree
			while index < len(_fen_tree):
				_fen_tree[index] += value
				index |= index + 1

	def _fen_query(self, end):
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		x = 0
		while end:
			x += _fen_tree[end - 1]
			end &= end - 1
		return x

	def _fen_findkth(self, k):
		_list_lens = self._list_lens
		if k < _list_lens[0]:
			return (0, k)
		if k >= self._len - _list_lens[-1]:
			return (len(_list_lens) - 1, k + _list_lens[-1] - self._len)
		if self._rebuild:
			self._fen_build()
		_fen_tree = self._fen_tree
		idx = -1
		for d in reversed(range(len(_fen_tree).bit_length())):
			right_idx = idx + (1 << d)
			if right_idx < len(_fen_tree) and k >= _fen_tree[right_idx]:
				idx = right_idx
				k -= _fen_tree[idx]
		return (idx + 1, k)

	def _delete(self, pos, idx):
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len -= 1
		self._fen_update(pos, -1)
		del _lists[pos][idx]
		_list_lens[pos] -= 1
		if _list_lens[pos]:
			_mins[pos] = _lists[pos][0]
		else:
			del _lists[pos]
			del _list_lens[pos]
			del _mins[pos]
			self._rebuild = True

	def _loc_left(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(lo, pos) = (-1, len(_lists) - 1)
		while lo + 1 < pos:
			mi = lo + pos >> 1
			if value <= _mins[mi]:
				pos = mi
			else:
				lo = mi
		if pos and value <= _lists[pos - 1][-1]:
			pos -= 1
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value <= _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def _loc_right(self, value):
		if not self._len:
			return (0, 0)
		_lists = self._lists
		_mins = self._mins
		(pos, hi) = (0, len(_lists))
		while pos + 1 < hi:
			mi = pos + hi >> 1
			if value < _mins[mi]:
				hi = mi
			else:
				pos = mi
		_list = _lists[pos]
		(lo, idx) = (-1, len(_list))
		while lo + 1 < idx:
			mi = lo + idx >> 1
			if value < _list[mi]:
				idx = mi
			else:
				lo = mi
		return (pos, idx)

	def add(self, value):
		_load = self._load
		_lists = self._lists
		_mins = self._mins
		_list_lens = self._list_lens
		self._len += 1
		if _lists:
			(pos, idx) = self._loc_right(value)
			self._fen_update(pos, 1)
			_list = _lists[pos]
			_list.insert(idx, value)
			_list_lens[pos] += 1
			_mins[pos] = _list[0]
			if _load + _load < len(_list):
				_lists.insert(pos + 1, _list[_load:])
				_list_lens.insert(pos + 1, len(_list) - _load)
				_mins.insert(pos + 1, _list[_load])
				_list_lens[pos] = _load
				del _list[_load:]
				self._rebuild = True
		else:
			_lists.append([value])
			_mins.append(value)
			_list_lens.append(1)
			self._rebuild = True

	def discard(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_right(value)
			if idx and _lists[pos][idx - 1] == value:
				self._delete(pos, idx - 1)

	def remove(self, value):
		_len = self._len
		self.discard(value)
		if _len == self._len:
			raise ValueError('{0!r} not in list'.format(value))

	def pop(self, index=-1):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		value = self._lists[pos][idx]
		self._delete(pos, idx)
		return value

	def bisect_left(self, value):
		(pos, idx) = self._loc_left(value)
		return self._fen_query(pos) + idx

	def bisect_right(self, value):
		(pos, idx) = self._loc_right(value)
		return self._fen_query(pos) + idx

	def count(self, value):
		return self.bisect_right(value) - self.bisect_left(value)

	def __len__(self):
		return self._len

	def __getitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		return self._lists[pos][idx]

	def __delitem__(self, index):
		(pos, idx) = self._fen_findkth(self._len + index if index < 0 else index)
		self._delete(pos, idx)

	def __contains__(self, value):
		_lists = self._lists
		if _lists:
			(pos, idx) = self._loc_left(value)
			return idx < len(_lists[pos]) and _lists[pos][idx] == value
		return False

	def __iter__(self):
		return (value for _list in self._lists for value in _list)

	def __reversed__(self):
		return (value for _list in reversed(self._lists) for value in reversed(_list))

	def __repr__(self):
		return 'SortedList({0})'.format(list(self))

class SegTree:

	def __init__(self, n):
		self.N = 1 << n.bit_length()
		self.tree = [0] * (self.N << 1)

	def update(self, i, j, v):
		i += self.N
		j += self.N
		while i <= j:
			if i % 2 == 1:
				self.tree[i] += v
			if j % 2 == 0:
				self.tree[j] += v
			(i, j) = (i + 1 >> 1, j - 1 >> 1)

	def query(self, i):
		v = 0
		i += self.N
		while i > 0:
			v += self.tree[i]
			i >>= 1
		return v

def SieveOfEratosthenes(limit):
	isPrime = [True] * (limit + 1)
	isPrime[0] = isPrime[1] = False
	primes = []
	for i in range(2, limit + 1):
		if not isPrime[i]:
			continue
		primes += [i]
		for j in range(i * i, limit + 1, i):
			isPrime[j] = False
	return primes

def main():
	mod = 1000000007
	starttime = datetime.datetime.now()
	if os.path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	tc = 1
	for _ in range(tc):
		n = ri()
		graph = [[] for i in range(n + 1)]
		cntdiffcolorededges = 0
		edges = []
		diffcoledges = {}
		for i in range(n - 1):
			(a, b) = ria()
			edges.append([a, b])
			graph[a].append(b)
			graph[b].append(a)
		col = [0] + ria()
		for (a, b) in edges:
			if col[a] != col[b]:
				cntdiffcolorededges += 2
				diffcoledges[a] = diffcoledges.get(a, 0) + 1
				diffcoledges[b] = diffcoledges.get(b, 0) + 1
		if cntdiffcolorededges == 0:
			ws('YES')
			wi(1)
			exit()
		for i in diffcoledges:
			if 2 * diffcoledges[i] == cntdiffcolorededges:
				ws('YES')
				wi(i)
				exit()
		ws('NO')
	endtime = datetime.datetime.now()
	time = (endtime - starttime).total_seconds() * 1000
	if os.path.exists('input.txt'):
		print('Time:', time, 'ms')

class FastReader(io.IOBase):
	newlines = 0

	def __init__(self, fd, chunk_size=1024 * 8):
		self._fd = fd
		self._chunk_size = chunk_size
		self.buffer = io.BytesIO()

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size=-1):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, self._chunk_size if size == -1 else size))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

class FastWriter(io.IOBase):

	def __init__(self, fd):
		self._fd = fd
		self.buffer = io.BytesIO()
		self.write = self.buffer.write

	def flush(self):
		os.write(self._fd, self.buffer.getvalue())
		(self.buffer.truncate(0), self.buffer.seek(0))

class FastStdin(io.IOBase):

	def __init__(self, fd=0):
		self.buffer = FastReader(fd)
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

class FastStdout(io.IOBase):

	def __init__(self, fd=1):
		self.buffer = FastWriter(fd)
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.flush = self.buffer.flush
sys.stdin = FastStdin()
sys.stdout = FastStdout()
main()


import sys
sys.setrecursionlimit(10 ** 9)

def dfs(a, pre=-1, par=None):
	global aa
	for i in adj[a]:
		if i == par:
			continue
		if pre == -1:
			dfs(i, it[i], a)
		elif pre != it[i]:
			aa = True
			return ''
		else:
			dfs(i, it[i], a)
n = int(input())
ed = []
adj = [[] for i in range(n)]
for _ in range(n - 1):
	(a, b) = map(int, input().split())
	ed.append([a - 1, b - 1])
	adj[a - 1].append(b - 1)
	adj[b - 1].append(a - 1)
it = list(map(int, input().split()))
st = False
for i in ed:
	if it[i[0]] != it[i[1]]:
		st = True
		e = i
		break
if not st:
	print('YES')
	print(1)
else:
	ans = True
	aa = False
	dfs(e[0])
	if aa == False:
		print('YES', e[0] + 1, sep='\n')
	else:
		aa = False
		dfs(e[1])
		if aa == False:
			print('YES')
			print(e[1] + 1)
		else:
			print('NO')


n = int(input())
u = []
v = []
for i in range(n - 1):
	(a, b) = map(int, input().split())
	u.append(a)
	v.append(b)
c = [0] + [int(x) for x in input().split()]
e = 0
dic = {}
for i in range(1, n + 1):
	dic[i] = 0

def plus(dic, n):
	if n in dic:
		dic[n] += 1
	else:
		dic[n] = 1
for i in range(n - 1):
	if c[u[i]] != c[v[i]]:
		e += 1
		dic[u[i]] += 1
		dic[v[i]] += 1
for i in range(1, n + 1):
	if dic[i] == e:
		print('YES', i, sep='\n')
		exit(0)
print('NO')


import math as mt
import sys, string
input = sys.stdin.readline
import random
from collections import deque, defaultdict
L = lambda : list(map(int, input().split()))
Ls = lambda : list(input().split())
M = lambda : map(int, input().split())
I = lambda : int(input())

def bfs(a):
	w = g[a]
	v = [0] * n
	for i in w:
		v[i] = 1
	v[a] = 1
	j = 0
	while j < len(w):
		k = w[j]
		for i in g[k]:
			if v[i] == 0:
				if l[i] == l[k]:
					w.append(i)
					v[i] = 1
				else:
					return False
		j += 1
	return True
n = I()
g = []
for i in range(n):
	g.append([])
x = []
for _ in range(n - 1):
	(a, b) = M()
	a -= 1
	b -= 1
	x.append((a, b))
	g[a].append(b)
	g[b].append(a)
l = L()
for i in range(n - 1):
	if l[x[i][0]] != l[x[i][1]]:
		if bfs(x[i][0]):
			print('YES')
			print(x[i][0] + 1)
			exit()
		if bfs(x[i][1]):
			print('YES')
			print(x[i][1] + 1)
			exit()
		else:
			print('NO')
			exit()
print('YES')
print('1')


n = int(input())
edges = [list(map(int, input().split())) for i in range(n - 1)]
c = list(map(int, input().split()))
u = [0] * n
v = 0
for (a, b) in edges:
	if c[a - 1] != c[b - 1]:
		u[a - 1] += 1
		u[b - 1] += 1
		v += 1
if v == max(u):
	print('YES', u.index(v) + 1, sep='\n')
else:
	print('NO')


N = int(input())
l = [[] for i in range(N)]
for i in range(N - 1):
	(u, v) = tuple((int(x) - 1 for x in input().split()))
	l[u].append(v)
	l[v].append(u)
c = [int(x) for x in input().split()]
root = -1

def dfs(l, c, now, past):
	global root
	if root != -1:
		return
	if c[now] != c[past]:
		tmp = 0
		for x in l[now]:
			if c[x] != c[now]:
				tmp += 1
		if tmp > 1:
			root = now
		else:
			root = past
	for nxt in l[now]:
		if nxt != past:
			dfs(l, c, nxt, now)
dfs(l, c, 0, 0)
if root == -1:
	print('YES')
	print(1)
	exit(0)
root_p = root
for sub in l[root_p]:
	root = -1
	l[sub].remove(root_p)
	dfs(l, c, sub, sub)
	if root != -1:
		print('NO')
		break
else:
	print('YES')
	print(root_p + 1)


def solve():
	n = int(input())
	edge = [[0, 0] for i in range(n)]
	for i in range(n - 1):
		edge[i] = list(map(int, input().split()))
	color = [0] + list(map(int, input().split()))
	cnt = 0
	diff = [0 for i in range(n + 1)]
	for i in range(n - 1):
		if color[edge[i][0]] != color[edge[i][1]]:
			cnt += 1
			diff[edge[i][0]] += 1
			diff[edge[i][1]] += 1
	for i in range(1, n + 1):
		if diff[i] == cnt:
			print('{0}\n{1}'.format('YES', i))
			return
	print('NO')
solve()


n = int(input())
adj = [[] for i in range(n)]
for i in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u - 1].append(v - 1)
	adj[v - 1].append(u - 1)
colors = [int(x) for x in input().split()]
t = {}

def is_good_tree(u, p):
	if (u, p) in t:
		return t[u, p]
	for v in adj[u]:
		if v == p:
			continue
		if colors[u] != colors[v]:
			return False
	result = all((is_good_tree(v, u) for v in adj[u] if v != p))
	t[u, p] = result
	return result
for u in range(n):
	if all((is_good_tree(v, u) for v in adj[u])):
		print('YES')
		print(u + 1)
		break
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	tree = [[] for _ in range(n + 1)]
	for _ in range(n - 1):
		(a, b) = map(int, input().split())
		tree[a].append(b)
		tree[b].append(a)
	arr = [0] + list(map(int, input().split()))
	(root1, root2) = (0, 0)
	for i in range(1, n + 1):
		for item in tree[i]:
			if arr[i] != arr[item]:
				root1 = i
				root2 = item
				break
		if root2:
			break
	if not root2:
		print('YES')
		print(1)
		exit()
	ans = 1
	vis = [0] * (n + 1)
	idx = [0] * (n + 1)
	vis[root1] = 1
	for item in tree[root1]:
		stack = [item]
		while stack:
			x = stack[-1]
			vis[x] = 1
			y = idx[x]
			if y == len(tree[x]):
				stack.pop()
			else:
				z = tree[x][y]
				if vis[z] == 0:
					if arr[x] != arr[z]:
						ans = 0
						break
					stack.append(z)
				idx[x] += 1
		if ans == 0:
			break
	if ans == 1:
		print('YES')
		print(root1)
		exit()
	ans = 1
	vis = [0] * (n + 1)
	idx = [0] * (n + 1)
	vis[root2] = 1
	for item in tree[root2]:
		stack = [item]
		while stack:
			x = stack[-1]
			vis[x] = 1
			y = idx[x]
			if y == len(tree[x]):
				stack.pop()
			else:
				z = tree[x][y]
				if vis[z] == 0:
					if arr[x] != arr[z]:
						ans = 0
						break
					stack.append(z)
				idx[x] += 1
		if ans == 0:
			break
	if ans:
		print('YES')
		print(root2)
	else:
		print('NO')
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


n = int(input())
(u, v) = ([], [])
for i in range(n - 1):
	(a, b) = list(map(int, input().split()))
	u.append(a)
	v.append(b)
colors = [0] + [int(x) for x in input().split()]
maximumDifference = 0
differences = {i: 0 for i in range(1, n + 1)}
for i in range(n - 1):
	vertex1 = u[i]
	vertex2 = v[i]
	if colors[vertex1] != colors[vertex2]:
		maximumDifference += 1
		differences[vertex1] += 1
		differences[vertex2] += 1
if maximumDifference in list(differences.values()):
	print('YES')
	print(list(differences.values()).index(maximumDifference) + 1)
else:
	print('NO')


read = lambda : map(int, input().split())
n = int(input())
ed = []
for i in range(n - 1):
	(u, v) = read()
	if u > v:
		(u, v) = (v, u)
	ed.append((u, v))
c = [0] + list(read())
edr = []
g = [list() for i in range(n + 1)]
ver = set()
for (u, v) in ed:
	if c[u] != c[v]:
		g[u].append(v)
		g[v].append(u)
		ver.add(u)
		ver.add(v)
root = 1
for i in range(1, n + 1):
	if len(g[i]) > 1:
		root = i
		break
	if len(g[i]) == 1:
		root = i
was = [0] * (n + 1)
was[root] = 1
for u in g[root]:
	was[u] = 1
for i in ver:
	if not was[i]:
		print('NO')
		exit()
print('YES')
print(root)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, random, time
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
mod = 10 ** 9 + 7

def LI():
	return list(map(int, input().split()))

def II():
	return int(input())

def LS():
	return input().split()

def S():
	return input()

def main():
	n = II()
	d = collections.defaultdict(list)
	t = []
	for _ in range(n - 1):
		(a, b) = LI()
		t.append([a, b])
	c = LI()
	r = []
	for (a, b) in t:
		d[a].append(b)
		d[b].append(a)
		if c[a - 1] != c[b - 1]:
			r = [a, b]
	if not r:
		print('YES')
		print(1)
		return
	for ri in r:
		rf = False
		for i in range(1, n + 1):
			if i == ri:
				continue
			ci = c[i - 1]
			for j in d[i]:
				if j == ri:
					continue
				if ci != c[j - 1]:
					rf = True
					break
			if rf:
				break
		if not rf:
			print('YES')
			print(ri)
			return
	print('NO')
main()


import sys
from collections import defaultdict
from collections import deque
from types import GeneratorType
input = sys.stdin.readline

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc

def get_adj_mat(src, dst):
	matrix = defaultdict(list)
	for (src_i, dst_i) in zip(src, dst):
		matrix[src_i].append(dst_i)
		matrix[dst_i].append(src_i)
	return matrix

@bootstrap
def set_nodes_status(node, good, seen, adj_mat, vals):
	(all_values_same, all_childs_good) = (True, True)
	for child in adj_mat[node]:
		if not seen[child]:
			seen[child] = True
			all_values_same = all_values_same and vals[child] == vals[node]
			yield set_nodes_status(child, good, seen, adj_mat, vals)
			all_childs_good = all_childs_good and good[child]
	good[node] = all_values_same and all_childs_good
	yield None

def find_bad_child(node, good, adj_mat, vals):
	bad_childs = []
	not_same_good_childs = []
	num_childs = 0
	for child in adj_mat[node]:
		num_childs += 1
		if good[child]:
			if not vals[node] == vals[child]:
				not_same_good_childs.append(child)
		else:
			bad_childs.append(child)
	good[node] = True
	if len(bad_childs) > 1:
		return -1
	elif len(bad_childs) == 1:
		if len(not_same_good_childs) > 0:
			return -1
		else:
			return bad_childs[0]
	else:
		return node

def walk(node, good, adj_mat, vals):
	while True:
		cand = find_bad_child(node, good, adj_mat, vals)
		if cand == -1:
			print('NO')
			return
		elif cand == node:
			print('YES')
			print(cand + 1)
			return
		else:
			node = cand

def solve(src, dst, vals):
	n = len(vals)
	adj_mat = get_adj_mat(src, dst)
	seen = [False] * n
	good = [False] * n
	root = 1
	seen[root] = True
	set_nodes_status(root, good, seen, adj_mat, vals)
	walk(root, good, adj_mat, vals)
n = int(input())
(src, dst) = ([], [])
for _ in range(n - 1):
	(src_i, dst_i) = [int(val) for val in input().split()]
	(src.append(src_i - 1), dst.append(dst_i - 1))
vals = [int(val) for val in input().split()]
solve(src, dst, vals)


n = int(input())
edges = []
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	edges.append([u, v])
ct = [0] + list(map(int, input().split()))
ds = [-1] + [0] * n
vs = 0
for (u, v) in edges:
	if ct[u] != ct[v]:
		ds[u] += 1
		ds[v] += 1
		vs += 1
if vs == max(ds):
	print('YES')
	print(ds.index(vs))
else:
	print('NO')


n = int(input())
e = [[0, 0] for i in range(n - 1)]
c = [0 for i in range(n)]
t = []
num = 0
for i in range(n - 1):
	inp = input().split()
	for j in range(2):
		e[i][j] = int(inp[j]) - 1
inp = input().split()
for i in range(n):
	c[i] = int(inp[i])
for i in range(n - 1):
	if c[e[i][0]] != c[e[i][1]]:
		if num == 0:
			t = e[i]
			num += 1
		else:
			if len(t) > 1 and t[1] not in e[i]:
				t.remove(t[1])
			if len(t) > 0 and t[0] not in e[i]:
				t.remove(t[0])
if num == 0:
	print('YES')
	print(1)
elif len(t) == 0:
	print('NO')
else:
	print('YES')
	print(t[0] + 1)


n = int(input())
e = []
for i in range(n - 1):
	e += [list(map(int, input().split()))]
	e[-1][0] -= 1
	e[-1][1] -= 1
c = list(map(int, input().split()))
root = {}
diff = 0
for i in range(n - 1):
	if c[e[i][0]] != c[e[i][1]]:
		root = {e[i][0], e[i][1]}
		diff = 1
		break
for i in range(n - 1):
	if c[e[i][0]] != c[e[i][1]]:
		root = root.intersection({e[i][0], e[i][1]})
if len(root) == 0 and diff == 1:
	print('NO')
else:
	print('YES')
	if len(root) == 0:
		print(1)
	else:
		for i in root:
			print(i + 1)
			break


n = int(input())
edges = list()
edges = []
for i in range(n - 1):
	edge = []
	edge = input().split(' ')
	edge = list(map(int, edge))
	edges.append(edge)
colors = []
colors = input().split(' ')
colors = list(map(int, colors))
colors.insert(0, 0)
if n < 3:
	print('YES')
	print(edges[0][0])
	exit()
commonedge = []
for edge in edges:
	if colors[edge[0]] != colors[edge[1]]:
		if len(commonedge) == 0:
			commonedge.append(edge[0])
			commonedge.append(edge[1])
		elif len(commonedge) == 2:
			if commonedge.count(edge[0]) == 0 and commonedge.count(edge[1]) == 0:
				print('NO')
				exit()
			elif commonedge.count(edge[1]) == 0:
				if commonedge[0] == edge[0]:
					del commonedge[1]
				else:
					del commonedge[0]
			elif commonedge[0] == edge[1]:
				del commonedge[1]
			else:
				del commonedge[0]
		elif commonedge.count(edge[0]) == 0 and commonedge.count(edge[1]) == 0:
			print('NO')
			exit()
print('YES')
if len(commonedge) > 0:
	print(commonedge[0])
else:
	print(edges[0][0])


from sys import stdin, stdout
from sys import setrecursionlimit
setrecursionlimit(10 ** 5)
n = int(stdin.readline())
visit = [0 for i in range(n + 1)]
edges = []
vertices = [[] for i in range(n + 1)]
d = {}
cnt = {}

def dfs(v, c):
	visit[v] = 1
	label = 1
	for u in vertices[v]:
		if not visit[u]:
			label = min(label, dfs(u, c))
			if not label:
				return label
	if colours[v] != c:
		return 0
	else:
		return label
for i in range(n - 1):
	(a, b) = map(int, stdin.readline().split())
	edges.append((a - 1, b - 1))
	vertices[a - 1].append(b - 1)
	vertices[b - 1].append(a - 1)
colours = list(map(int, stdin.readline().split()))
label = 0
for i in range(n - 1):
	(a, b) = edges[i]
	if colours[a] != colours[b]:
		break
else:
	label = 1
	stdout.write('YES\n1')
if not label:
	visit[a] = 1
	for v in vertices[a]:
		if not dfs(v, colours[v]):
			break
	else:
		label = 1
		stdout.write('YES\n' + str(a + 1))
	visit = [0 for i in range(n + 1)]
	if not label:
		visit[b] = 1
		for v in vertices[b]:
			if not dfs(v, colours[v]):
				stdout.write('NO')
				break
		else:
			label = 1
			stdout.write('YES\n' + str(b + 1))


import sys
n = int(sys.stdin.readline())
edges = [[int(x) for x in sys.stdin.readline().split()] for _ in range(n - 1)]
colors = sys.stdin.readline().split()
res = None
for edge in edges:
	if colors[edge[0] - 1] != colors[edge[1] - 1]:
		if res is None:
			res = list(edge)
		else:
			res = [x for x in res if x in edge]
			if len(res) == 0:
				break
if res is None:
	print('YES\n1')
else:
	print('NO' if len(res) == 0 else 'YES\n' + str(res[0]))


def main():
	n = int(input())
	pairs = []
	for i in range(n - 1):
		(a, b) = list(map(int, input().split()))
		pairs.append([a - 1, b - 1])
	colors = list(map(int, input().split()))
	bad_pairs_count = 0
	bad_points_counts = {0: 0}
	for (a, b) in pairs:
		if colors[a] != colors[b]:
			bad_pairs_count += 1

			def add(x):
				if x not in bad_points_counts:
					bad_points_counts[x] = 0
				bad_points_counts[x] += 1
			add(a)
			add(b)
	for (k, v) in bad_points_counts.items():
		if v == bad_pairs_count:
			print('YES')
			print(k + 1)
			return
	print('NO')
main()


import sys

def answer(n, u, v, colors):
	suspect = []
	for i in range(n - 1):
		if colors[u[i] - 1] != colors[v[i] - 1]:
			suspect.append([u[i], v[i]])
	if len(suspect) == 0:
		print('YES')
		print('1')
		return
	s = set(suspect[0])
	for tup in suspect:
		s &= set(tup)
	if len(s) == 0:
		print('NO')
		return
	else:
		print('YES')
		print(s.pop())
	return

def main():
	n = int(sys.stdin.readline())
	u = [0 for _ in range(n)]
	v = [0 for _ in range(n)]
	for i in range(n - 1):
		(u[i], v[i]) = map(int, sys.stdin.readline().split())
	colors = list(map(int, sys.stdin.readline().split()))
	answer(n, u, v, colors)
	return
main()


from collections import defaultdict
n = int(input())
graph = defaultdict(list)
edges = []
for i in range(n - 1):
	(u, v) = map(int, input().split())
	graph[u].append(v)
	graph[v].append(u)
	edges.append((u, v))
c = [int(i) for i in input().strip().split()]
colors = {i + 1: v for (i, v) in enumerate(c)}
colors[0] = -1
good = set()

def start(start):
	nebs = graph[start]
	for n in nebs:
		if not dfs(n, set([start]), colors[n]):
			return False
	return True

def dfs(start, visited, want):
	visited.add(start)
	if colors[start] != want:
		return False
	for neb in graph[start]:
		if neb not in visited:
			if not dfs(neb, visited, want):
				return False
	return True
found = False
ans = -1
all_same = True
for (u, v) in edges:
	if colors[u] != colors[v]:
		all_same = False
		split_with_u = start(u)
		split_with_v = start(v)
		if split_with_u:
			found = True
			ans = u
			break
		elif split_with_v:
			found = True
			ans = v
			break
		else:
			break
if all_same:
	print('YES')
	print(n)
elif found:
	print('YES')
	print(ans)
else:
	print('NO')


N = int(input())
G = [[] for i in range(N)]
d = []
for i in range(N - 1):
	(a, b) = map(int, input().split())
	(a, b) = (a - 1, b - 1)
	G[a].append(b)
	G[b].append(a)
	d.append((a, b))
C = list(map(int, input().split()))
num = 0
for i in range(N - 1):
	if C[d[i][0]] != C[d[i][1]]:
		num += 1
for i in range(N):
	s = 0
	for j in G[i]:
		if C[i] != C[j]:
			s += 1
	if s == num:
		print('YES')
		print(i + 1)
		break
else:
	print('NO')


import random
n = int(input())
d = {}
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	if u not in d:
		d[u] = [v]
	else:
		d[u].append(v)
	if v not in d:
		d[v] = [u]
	else:
		d[v].append(u)
c = [0] + list(map(int, input().split()))
start = random.randint(1, n)
stack = [(start, start)]
picked = -1
parent = []
visited = set()
while stack:
	(p, parent) = stack.pop()
	visited.add(p)
	if c[p] != c[parent] and parent != picked:
		if picked != -1:
			print('NO')
			break
		else:
			picked = p
	for x in d[p]:
		if x not in visited:
			stack.append((x, p))
else:
	print('YES')
	if picked == -1:
		picked = 1
	print(picked)


n = int(input())
e = [list(map(int, input().split())) for i in range(n - 1)]
c = list(map(int, input().split()))
(ec, v) = ([0] * n, 0)
for (ea, eb) in e:
	if c[ea - 1] != c[eb - 1]:
		ec[ea - 1] += 1
		ec[eb - 1] += 1
		v += 1
if v == max(ec):
	print('YES', ec.index(v) + 1, sep='\n')
else:
	print('NO')


import sys

def minp():
	return sys.stdin.readline().strip()

def mint():
	return int(minp())

def mints():
	return map(int, minp().split())

def solve():
	n = mint()
	e = [[] for i in range(n + 1)]
	for i in range(n - 1):
		(u, v) = mints()
		e[u].append(v)
		e[v].append(u)
	c = list(mints())
	start = None
	for i in range(1, n + 1):
		ci = c[i - 1]
		for j in e[i]:
			if c[j - 1] != ci:
				start = (i, j)
				break
		if start != None:
			break
	if start == None:
		print('YES')
		print(1)
		return
	for s in start:
		was = [False] * (n + 1)
		ql = 0
		q = []
		was[s] = True
		for i in e[s]:
			was[i] = True
			q.append((i, c[i - 1]))
		ok = True
		while ql < len(q):
			(v, cc) = q[ql]
			ql += 1
			for i in e[v]:
				if was[i]:
					continue
				was[i] = True
				if c[i - 1] != cc:
					ok = False
				q.append((i, cc))
		if ok:
			print('YES')
			print(s)
			return
	print('NO')
solve()


import sys
import collections
import itertools
n = int(sys.stdin.readline())
graph = collections.defaultdict(list)
for _ in range(n - 1):
	(u, v) = map(int, str.split(sys.stdin.readline()))
	graph[u].append(v)
	graph[v].append(u)
colors = tuple(map(int, str.split(sys.stdin.readline())))
root = None
root_possible = []
for node in graph:
	diff_subs = []
	for sub_node in graph[node]:
		if colors[node - 1] != colors[sub_node - 1]:
			diff_subs.append(sub_node)
	if len(diff_subs) > 1:
		if root is None:
			root = node
		else:
			print('NO')
			exit()
	elif len(diff_subs) == 1:
		root_possible.append((node, diff_subs[0]))
root_possible_set = set(itertools.chain.from_iterable(root_possible))
if root:
	print('YES')
	print(root)
elif not root_possible:
	print('YES')
	print(1)
elif len(root_possible_set) == 2:
	print('YES')
	print(next(iter(root_possible_set)))
else:
	print('NO')


import os
import sys
from io import BytesIO, IOBase
import heapq as h
from bisect import bisect_left
from types import GeneratorType
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		import os
		self.os = os
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = self.os.read(self._fd, max(self.os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			self.os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
import time
start_time = time.time()
import collections as col
import math, string
from functools import reduce

def getInts():
	return [int(s) for s in input().split()]

def getInt():
	return int(input())

def getStrs():
	return [s for s in input().split()]

def getStr():
	return input()

def listStr():
	return list(input())
MOD = 10 ** 9 + 7

def solve():
	N = getInt()
	graph = col.defaultdict(set)
	edges = []
	for n in range(N - 1):
		(U, V) = getInts()
		if U > V:
			(U, V) = (V, U)
		U -= 1
		V -= 1
		graph[U].add(V)
		graph[V].add(U)
		edges.append((U, V))
	cols = getInts()
	diff_cols = col.defaultdict(int)
	total = 0
	for (U, V) in edges:
		if cols[U] != cols[V]:
			diff_cols[U] += 1
			diff_cols[V] += 1
			total += 1
	if total == 1:
		print('YES')
		print(edges[0][1] + 1)
		return
	if not diff_cols:
		print('YES')
		print('1')
		return
	root = -10 ** 9
	for (key, val) in diff_cols.items():
		if val > 1:
			if val != total:
				print('NO')
				return
			else:
				root = key + 1
				break
	if root > 0:
		print('YES')
		print(root)
		return
	print('NO')
	return
solve()


from collections import defaultdict, deque
n = int(input())
adj_dict = defaultdict(list)
for i in range(n - 1):
	(u, v) = [int(i) for i in input().split()]
	adj_dict[u].append(v)
	adj_dict[v].append(u)
color_list = [0] + [int(i) for i in input().split()]
if len(set(color_list[1:])) == 1:
	print('YES')
	print(1)
else:
	leaf_count = 0
	candidate = []
	for i in adj_dict:
		forxflag = False
		if len(adj_dict[i]) == 1:
			visited = set()
			leaf_count += 1
			initial_color = color_list[i]
			q = deque([i])
			while q:
				cur = q[0]
				q.popleft()
				visited.add(cur)
				if color_list[cur] != initial_color:
					candidate.append(cur)
					break
				for x in adj_dict[cur]:
					if x not in visited:
						q.append(x)
						visited.add(x)
						if color_list[x] != initial_color:
							candidate.append(x)
							forxflag = True
							break
				if forxflag:
					break
		if leaf_count == 2:
			break

	def verify_candidate(u):
		for v in adj_dict[u]:
			initial_color = color_list[v]
			visited = set([u])
			q = deque([v])
			while q:
				cur = q[0]
				q.popleft()
				visited.add(cur)
				if color_list[v] != initial_color:
					return False
				for x in adj_dict[cur]:
					if x not in visited:
						q.append(x)
						visited.add(x)
						if color_list[x] != initial_color:
							return False
		return True
	if verify_candidate(candidate[0]):
		print('YES')
		print(candidate[0])
	elif verify_candidate(candidate[1]):
		print('YES')
		print(candidate[1])
	else:
		print('NO')


n = int(input())
edges = []
for _ in range(n - 1):
	(u, v) = [int(el) for el in input().split()]
	edges.append((u - 1, v - 1))
color = [int(el) for el in input().split()]
edge = None
for (v, u) in edges:
	if color[v] != color[u]:
		if edge is None:
			edge = (v, u)
		else:
			(vv, uu) = edge
			if vv == v or vv == u:
				edge = (vv, -1)
			elif uu == v or uu == u:
				edge = (uu, -1)
			else:
				edge = (-1, -1)
if edge is None:
	print('YES')
	print(1)
elif edge == (-1, -1):
	print('NO')
else:
	print('YES')
	print(str(edge[0] + 1))


n = int(input())
a = {}
color = {}
sec = []
for i in range(1, n + 1):
	a[i] = []
for i in range(n - 1):
	(u, v) = map(int, input().split())
	a[u].append(v)
	a[v].append(u)
	sec.append((u, v))
b = list(map(int, input().split()))

def check_sub_color(current_node, color=0, parent=0):
	if not color:
		color = b[current_node - 1]
	elif b[current_node - 1] != color:
		return False
	for node in a[current_node]:
		if node != parent and (not check_sub_color(node, color, current_node)):
			return False
	return True

def check(i):
	for t in a[i]:
		if t != i and (not check_sub_color(t, parent=i)):
			return False
	return True
index = -1
f = False
for line in sec:
	if b[line[0] - 1] != b[line[1] - 1]:
		f = True
		if check(line[0]):
			index = line[0]
		elif check(line[1]):
			index = line[1]
		break
if not f:
	index = 1
if index != -1:
	print('YES')
	print(index)
else:
	print('NO')


n = int(input())
edges = []
for i in range(n - 1):
	e = tuple(map(int, input().split()))
	edges.append(e)
c = list(map(int, input().split()))
edges_dc = []
for e in edges:
	if c[e[0] - 1] != c[e[1] - 1]:
		edges_dc.append(e)
roots = set()
for e in edges_dc:
	x = set(e)
	if len(roots) == 1:
		if len(x.intersection(roots)) == 0:
			print('NO')
			break
	elif len(roots) == 0:
		roots = x
	elif len(roots) == 2:
		roots = x.intersection(roots)
		if len(roots) == 0:
			print('NO')
			break
else:
	print('YES')
	if len(roots) == 0:
		roots.add(1)
	print(roots.pop())


from math import sqrt, gcd, ceil, floor, log, factorial
from itertools import permutations, combinations
from collections import Counter, defaultdict
import collections, sys, threading
import collections, sys, threading
sys.setrecursionlimit(10 ** 9)
threading.stack_size(10 ** 8)

def ii():
	return int(input())

def si():
	return input()

def mi():
	return map(int, input().split())

def msi():
	return map(str, input().split())

def li():
	return list(mi())

def solve():

	def dfs(node, g, visited, res):
		visited[node] = 1
		if res == []:
			res.append(c[node])
			for i in g[node]:
				if visited[i] == 0:
					dfs(i, g, visited, res)
		elif c[node] != res[-1]:
			res.append(-1)
			return
		else:
			res.append(c[node])
			for i in g[node]:
				if visited[i] == 0:
					dfs(i, g, visited, res)
	n = ii()
	g = []
	for _ in range(n - 1):
		(u, v) = mi()
		g.append([u, v])
	c = [0] + li()
	flag = 0
	res = []
	for edge in g:
		if c[edge[0]] != c[edge[1]]:
			res.append([edge[0], edge[1]])
	if len(res) == 0:
		print('YES')
		print(1)
	else:
		ans = res[0]
		for i in range(1, len(res)):
			ans = list(set(ans).intersection(set(res[i])))
		if len(ans) == 0:
			print('NO')
		else:
			print('YES')
			print(ans[0])
threading.Thread(target=solve).start()


n = int(input())
adj = [[] for _ in range(n)]
for _ in range(n - 1):
	(u, v) = map(int, input().split())
	adj[u - 1].append(v - 1)
	adj[v - 1].append(u - 1)
col = list(map(int, input().split()))

def is_single_color(s, i):
	vis = set([s])
	(comp, cur) = ([s], 0)
	while cur < len(comp):
		v = comp[cur]
		cur += 1
		for nv in adj[v]:
			if nv != i and nv not in vis:
				vis.add(nv)
				comp.append(nv)
	return all((col[v] == col[s] for v in comp))

def check(s):
	if all((is_single_color(v, s) for v in adj[s])):
		print('YES')
		print(s + 1)
		exit()
for v in range(n):
	for nv in adj[v]:
		if col[nv] != col[v]:
			check(nv)
			check(v)
			print('NO')
			exit()
print('YES')
print(1)