# 制約チェック N = int(input()) assert 1 <= N and N <= 200000 S = list(map(int, input().split())) for i in range(N): assert 0 <= S[i] and S[i] <= 1_000_000_000 parent = list(range(N+1)) def find(x: int): while parent[x] != x: parent[x] = parent[parent[x]] x = parent[x] return x def union(x: int, y: int): x = find(x) y = find(y) if x == y: return False parent[y] = x return True for i in range(N-1): line = list(map(int, input().split())) assert len(line) == 2 a, b = line assert 1 <= a and a <= N assert 1 <= b and b <= N assert union(a, b)