import sys sys.setrecursionlimit(200050) N = int(input()) AB = [list(map(int,input().split())) for _ in range(N-1)] C = list(map(int,input().split())) E = [[] for _ in range(N)] for a,b in AB: a -= 1; b -= 1 E[a].append(b) E[b].append(a) ans = 0 def dfs(u,p): global ans cnt = 0 for v in E[u]: if v != p: dfs(v,u) if C[v] == 0: cnt += 1 if cnt % 2 == 1: C[u] ^= 1 ans += cnt dfs(0,-1) if C[0] == 1: print(ans) else: print(-1)