from collections import deque n = int(input()) edges = [[] for _ in range(n)] for _ in range(n - 1): u, v = map(int, input().split()) u -= 1 v -= 1 edges[u].append(v) edges[v].append(u) cnt = 0 for i in range(n): if len(edges[i]) == 1: s = i cnt += 1 if cnt == 2: print("Yes") exit() queue = deque() queue.append((s, -1)) dist = [-1] * n dist[s] = 0 bef = [-1] * n while queue: pos, bpos = queue.popleft() for npos in edges[pos]: if npos == bpos: continue elif dist[npos] != -1: continue dist[npos] = dist[pos] + 1 bef[npos] = pos queue.append((npos, pos)) if dist[pos] % 2 == 1: print("No") exit() d = dist[pos] // 2 for _ in range(d): pos = bef[pos] queue = deque() queue.append((pos, -1)) dist = [-1] * n dist[pos] = 0 while queue: pos, bpos = queue.popleft() cnt = 0 for npos in edges[pos]: if npos == bpos: continue elif dist[npos] != -1: continue cnt += 1 dist[npos] = dist[pos] + 1 queue.append((npos, pos)) if bpos != -1 and cnt > 1: print("No") exit() for i in range(n): if len(edges[i]) == 1 and dist[i] != d: print("No") exit() print("Yes")