I,R=input,range def S(n): return abs(int(n)-1) def J(): return map(S,I().split()) N=int(I()) E=[set()for i in R(N)] for i in R(N-1): a,b=J() E[a].add(b),E[b].add(a) C=list(J()) A=[0]*N S=[0]*N L=set() for i in R(N): if len(E[i])<2:L.add(i) while len(L): M=set() for i in L: if len(E[i]): j=E[i].pop() S[j]+=C[i] A[j]+=A[i] E[j].remove(i) M.add(j) for j in M: A[j]+=S[j] C[j]=(C[j]+S[j])%2 L=M print([A[j],-1][C[j]])