import sys
sys.setrecursionlimit(5*10**5)
input = sys.stdin.readline
from collections import defaultdict, deque, Counter
from heapq import heappop, heappush
from bisect import bisect_left, bisect_right
from math import gcd

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

c = list(map(int,input().split()))
cnt = 0
def dfs(crr,pre):
  global cnt
  for nxt in graph[crr]:
    if nxt == pre: continue
    dfs(nxt,crr)
  if crr != 0 and c[crr] == 0:
    cnt += 1
    c[crr] ^= 1
    c[pre] ^= 1

dfs(0, -1)
if sum(c) == n:
  print(cnt)
else:
  print(-1)