import sys sys.setrecursionlimit(10**6) N = int(input()) G = {i:[] for i in range(1,N+1)} for _ in range(N-1): a,b = map(int,input().split()) G[a].append(b) G[b].append(a) C = [-1]+list(map(int,input().split())) cnt = 0 def dfs(x,p): global cnt for y in G[x]: if y==p:continue dfs(y,x) if x!=1 and C[x]==0: C[x] = 1 C[p] = 1-C[p] cnt += 1 dfs(1,0) if C[1]==0: print(-1) else: print(cnt)