n = int(input()) adj = [[] for _ in range(n)] for i in range(n-1): a,b = map(int, input().split()) adj[a-1].append(b-1) adj[b-1].append(a-1) c = list(map(int, input().split())) # for i in range(n): print(adj[i]) q = [(0, 0)] pars = [-1] * n route=[] while q: v, par = q.pop() if pars[v] != -1: continue pars[v] = par route.append(v) for nv in adj[v]: if nv == par: continue q.append((nv, v)) # print(route) # print(pars) ans = 0 for v in reversed(route): if v == 0: continue par = pars[v] if not c[v] % 2: c[par] += 1 ans += 1 # print(c) if not c[0] % 2: print(-1) else: print(ans)