def dfs(N, adj, root): stack = [root] parent = [-1] * N parent[root] = root depth = [0] * N while stack: v = stack.pop() for nv in adj[v]: if parent[nv] == -1: parent[nv] = v depth[nv] = depth[v] + 1 stack.append(nv) return parent, depth def main(): N = int(input()) adj = [[] for _ in range(N)] for _ in range(N - 1): u, v = map(int, input().split()) u -= 1; v -= 1 adj[u].append(v) adj[v].append(u) _, depth_0 = dfs(N, adj, 0) root = max(range(N), key=lambda i: depth_0[i]) parent, depth = dfs(N, adj, root) dist = max(depth) leaves = [v for v in range(N) if len(adj[v]) == 1] if dist % 2 == 1: if len(leaves) == 2: print("Yes") else: print("No") else: end = max(range(N), key=lambda i: depth[i]) cent = end for _ in range(dist // 2): cent = parent[cent] _, dists = dfs(N, adj, cent) for l in leaves: if dists[l] != dist // 2: print("No") exit() print("Yes") main()