N = int(input()) graph = [[] for _ in range(N+1)] for _ in range(N-1): a, b = map(int, input().split()) graph[a].append(b) graph[b].append(a) C = [0]+list(map(int, input().split())) parent = [-1]*(N+1) task = [1] for v in task: for u in graph[v]: if parent[u] == -1: task.append(u) parent[u] = v ans = 0 for v in task[1:][::-1]: if C[v]: continue C[parent[v]] ^= 1 C[v] = 1 ans += 1 print(ans if C[1] else -1)