import java.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayDeque; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Queue; public class Main { public static void main(String[] args) throws Exception { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] sa = br.readLine().split(" "); int n = Integer.parseInt(sa[0]); List> list = new ArrayList<>(n); for (int i = 0; i < n; i++) { list.add(new ArrayList<>()); } for (int i = 0; i < n - 1; i++) { sa = br.readLine().split(" "); int a = Integer.parseInt(sa[0]) - 1; int b = Integer.parseInt(sa[1]) - 1; list.get(a).add(b); list.get(b).add(a); } br.close(); int c1 = 0; int c3 = 0; for (int i = 0; i < n; i++) { if (list.get(i).size() == 1) { c1++; } if (list.get(i).size() > 2) { c3++; } } if (c1 == 2 && c3 == 0) { System.out.println("Yes"); return; } int[] d = new int[n]; Arrays.fill(d, -1); Queue que = new ArrayDeque<>(); for (int i = 0; i < n; i++) { if (list.get(i).size() == 1) { d[i] = 0; que.add(i); } } while (!que.isEmpty()) { int cur = que.poll(); for (int next : list.get(cur)) { if (d[next] == -1) { que.add(next); d[next] = d[cur] + 1; } } } int max = 0; for (int i = 0; i < n; i++) { if (d[i] > max) { max = d[i]; } } int c = -1; for (int i = 0; i < n; i++) { if (d[i] == max) { if (c != -1) { System.out.println("No"); return; } c = i; } } d = new int[n]; Arrays.fill(d, -1); d[c] = 0; que = new ArrayDeque<>(); que.add(c); while (!que.isEmpty()) { int cur = que.poll(); for (int next : list.get(cur)) { if (d[next] == -1) { que.add(next); d[next] = d[cur] + 1; } } } for (int i = 0; i < n; i++) { if (list.get(i).size() == 1) { if (d[i] != c) { System.out.println("No"); return; } } else { if (d[i] == c) { System.out.println("No"); return; } } } System.out.println("Yes"); } }