import java.io.PrintWriter import java.util.* import kotlin.math.* fun PrintWriter.solve() { val n = nextInt() val adj = Array(n) { mutableListOf() } for (i in 0 until n - 1) { val v1 = nextInt() - 1 val v2 = nextInt() - 1 adj[v1].add(v2) adj[v2].add(v1) } val lst = mutableListOf() for (i in 0 until n) { if (adj[i].count() >= 3) { lst.add(i) } } if (lst.count() >= 2) { println("No") } else if (lst.count() == 0) { println("Yes") } else { val lens = mutableSetOf() val que: Queue> = ArrayDeque() que.add(Triple(lst[0], -1, 0)) while (que.count() > 0) { val (v, p, d) = que.poll() var isleaf = true for (w in adj[v]) { if (w != p) { isleaf = false que.add(Triple(w, v, d + 1)) } } if (isleaf) { lens.add(d) } } println(if (lens.count() == 1) "Yes" else "No") } } fun main() { val writer = PrintWriter(System.out, false) writer.solve() writer.flush() } // region Scanner private var st = StringTokenizer("") private val br = System.`in`.bufferedReader() fun next(): String { while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine()) return st.nextToken() } fun nextInt() = next().toInt() fun nextLong() = next().toLong() fun nextLine() = br.readLine() fun nextDouble() = next().toDouble() // endregion