import sys from collections import deque, Counter input = sys.stdin.buffer.readline def bfs(N, T, s, return_all_dist=False): dist = [None] * N dist[s] = 0 d = deque([s]) while d: v = d.popleft() dx = dist[v] + 1 for x in T[v]: if dist[x] is not None: continue dist[x] = dx d.append(x) if return_all_dist: return dist else: max_dist = max(dist) return dist.index(max_dist), max_dist def med_tree(N, T): u, _ = bfs(N, T, 0) v, max_dist = bfs(N, T, u) if max_dist % 2: return None med_dist = max_dist // 2 dist_u = bfs(N, T, u, return_all_dist=True) dist_v = bfs(N, T, v, return_all_dist=True) for i, (du, dv) in enumerate(zip(dist_u, dist_v)): if du == dv == med_dist: return i def solve(N, T): leaves_num = sum([len(t) == 1 for t in T]) if leaves_num == 2: # 直線 return True med = med_tree(N, T) if med is None: return False ct_dist_med = Counter(bfs(N, T, med, return_all_dist=True)) del ct_dist_med[0] return len(set(ct_dist_med.values())) == 1 N = int(input()) T = [[] for _ in range(N)] for _ in range(N - 1): a, b = (int(x) - 1 for x in input().split()) T[a].append(b) T[b].append(a) print("Yes" if solve(N, T) else "No")