def main(): N = int(input()) graphs = [[] for _ in range(N)] for _ in range(N-1): dep, dest = map(lambda n: int(n)-1, input().split()) graphs[dep].append(dest) graphs[dest].append(dep) color = list(map(int, input().split())) if color.count(0) % 2: print(-1) return moved = set() searched = set() stack = [] stack.append([0, None]) moved.add(0) change_ctr = 0 while stack: ctr_child = 0 current_notice_node, notice_node_parent = stack[-1] for node_idx in graphs[current_notice_node]: if node_idx not in moved: stack.append((node_idx, current_notice_node)) moved.add(node_idx) ctr_child += 1 if ctr_child == 0: current_node_idx, parent_idx = stack.pop() if color[current_node_idx] == 0: if parent_idx is not None: color[current_node_idx] = 1 color[parent_idx] ^= 1 change_ctr += 1 else: print(-1) return searched.add(current_node_idx) print(change_ctr) if __name__ == "__main__": main()