I,R=input,range def S(n): return 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()) 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() C[j]+=C[i] E[j].remove(i) M.add(j) L=M print([-C[j],-1][C[j]%2])