N = int(input()) graph = [[] for _ in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) C = [0]+list(map(int, input().split())) parent = [-1]*(N+1) task = [1] for v in task: for u in graph[v]: if parent[v] == u: continue task.append(u) parent[u] = v ans = 0 task = [N+1, 1] while task: t = task.pop() if t > N: t -= N if t == 1: continue if not C[t]: C[t] ^= 1 C[parent[t]] ^= 1 ans += 1 else: for u in graph[t]: if u == parent[t]: continue task.append(u+N) task.append(u) print(ans if C[1] else -1)