n = int(input()) e = [[] for i in range(n)] for _ in range(n-1): a,b = [int(x)-1 for x in input().split()] e[a].append(b) e[b].append(a) C = list(map(int,input().split())) ans = 0 topo = [] vis = [0]*n par = [-1]*n q = [0] vis[0] = 1 while q: now = q.pop() topo.append(now) for nex in e[now]: if vis[nex]: continue vis[nex] = 1 par[nex] = now q.append(nex) for now in topo[::-1]: if now == 0: break if C[now]: continue C[now] = 1 C[par[now]] ^= 1 ans += 1 if C[0] == 0: ans = -1 print(ans)