import java.util.Scanner; import java.util.List; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; import java.util.PriorityQueue; import java.util.Queue; import java.util.Comparator; public class No1424 { private static int N; private static HashMap> Edge; private static List S; public static void main(String[] args) { Scanner scan = new Scanner(System.in); N = scan.nextInt(); Edge = new HashMap>(); for (int i=0; i < N-1; i++) { int v = scan.nextInt() - 1; int u = scan.nextInt() - 1; Edge.getOrDefault(v, new ArrayList()).add(u); Edge.getOrDefault(u, new ArrayList()).add(v); } scan.close(); S = new ArrayList(); for (int i=0; i < N; i++) { if (Edge.containsKey(i) && Edge.get(i).size() == 1) { S.add(i); } } int res = -1; for (int i=0; i < S.size()-1; i++) { int v = getPath(S.get(i), i); if (v < 0) { System.out.println("No"); return; } else if (res < 0) { res = v; } else if (res != v) { System.out.println("No"); return; } } System.out.println("Yes"); } private static class MyComparator implements Comparator { public int compare(Object obj1, Object obj2) { Integer[] num1 = (Integer[])obj1; Integer[] num2 = (Integer[])obj2; if(num1[0] > num2[0]) { return 1; } else if(num1[0] < num2[0]) { return -1; } else{ return 0; } } } private static int getPath(int s, int i) { int[] D = new int[N]; Arrays.fill(D, Integer.MAX_VALUE); D[s] = 0; Queue q = new PriorityQueue(new MyComparator()); q.add(new Integer[] {0, s}); while (q.size() > 0) { Integer[] c = q.poll(); if (c[0] > D[c[1]]) { continue; } for (int p : Edge.get(c[1])) { if (D[p] > D[c[1]] + 1) { D[p] = D[c[1]] + 1; q.add(new Integer[] {D[p], p}); } } } int res = -1; for (int e : S.subList(i+1, S.size())) { if (res < 0) { res = D[e]; } else if (res != D[e]) { return -1; } } return res; } }