N = int(input()) G = [[] for _ in range(N)] for _ in range(N - 1): a,b = map(int,input().split()) a -= 1 b -= 1 G[a].append(b) G[b].append(a) c = list(map(int,input().split())) stack = [(0,-1),(~0,-1)] ans = 0 while stack: now,parent = stack.pop() if now < 0: now = ~now for v in G[now]: if v != parent: stack.append((v,now)) stack.append((~v,now)) else: if now == 0: if c[now] == 1: print(ans) else: print(-1) break else: if c[now] == 0: ans += 1 c[now] = 1 c[parent] ^= 1