import sys from collections import deque input = sys.stdin.buffer.readline n = int(input()) graph = [[] for _ in range(n)] deg1 = [0] * n deg2 = [0] * n for _ in range(n - 1): a, b = map(int, input().split()) a, b = a - 1, b - 1 graph[a].append(b) graph[b].append(a) deg1[a] += 1 deg1[b] += 1 kouho = deque() haji = [] dist1 = [-1] * n done = [0] * n for i in range(n): if deg1[i] == 1: haji.append(i) def ok(): print("Yes") exit() def ng(): print("No") exit() # graph and n is necessary def dfs(start): par = [-1] * n depth = [-1] * n size = [0] * n stack = [] euler = [] stack.append(~start) stack.append(start) depth[start] = 0 while stack: v = stack.pop() if v >= 0: d = depth[v] euler.append(v) for u in graph[v]: if par[v] == u: continue par[u] = v depth[u] = d + 1 stack.append(~u) stack.append(u) else: a = ~v size[a] = 1 for u in graph[a]: if u == par[a]: continue size[a] += size[u] return par, size, euler par, size, euler = dfs(0) grav = [] for v in euler: flag = 1 if n - size[v] >= n // 2: continue for u in graph[v]: if u == par[v]: continue if size[u] >= n // 2: flag = 0 if flag: grav.append(v) assert len(grav) <= 2 # deque is necessary. # n, graph, start is necessary def BFS(grav): dist = [-1] * n que = deque() for v in grav: que.append(v) dist[v] = 0 while que: v = que.popleft() d = dist[v] for u in graph[v]: if dist[u] == -1: dist[u] = d + 1 que.append(u) return dist dist = BFS(grav) temp = dist[haji[0]] for v in haji: if dist[v] != temp: ng() ok()