import sys input = lambda :sys.stdin.readline()[:-1] ni = lambda :int(input()) na = lambda :list(map(int,input().split())) yes = lambda :print("yes");Yes = lambda :print("Yes");YES = lambda : print("YES") no = lambda :print("no");No = lambda :print("No");NO = lambda : print("NO") ####################################################################### n = ni() g = [[] for i in range(n)] deg = [0] * n for _ in range(n-1): a,b = na() a-=1 b-=1 g[a].append(b) g[b].append(a) deg[a] += 1 deg[b] += 1 c = [i^1 for i in na()] p = [i for i in range(n) if deg[i] == 1] ans = 0 while p: x = p.pop() #print(p, x) deg[x] -= 1 for y in g[x]: if deg[y] >= 1: deg[y] -= 1 if deg[y] == 1: p.append(y) if deg[y] >= 1 and c[x] == 1: c[x] ^= 1 c[y] ^= 1 ans += 1 if sum(c) == 2: print(ans+1) elif sum(c) == 1: print(-1) else: print(ans)