{"raw_statement":[{"iden":"statement","content":"Consider a rooted tree. A rooted tree has one special vertex called the root. All edges are directed from the root. Vertex _u_ is called a _child_ of vertex _v_ and vertex _v_ is called a _parent_ of vertex _u_ if there exists a directed edge from _v_ to _u_. A vertex is called a _leaf_ if it doesn't have children and has a parent.\n\nLet's call a rooted tree a _spruce_ if its every non-leaf vertex has at least 3 leaf children. You are given a rooted tree, check whether it's a spruce.\n\nThe definition of a rooted tree can be found [here](https://goo.gl/1dqvzz)."},{"iden":"input","content":"The first line contains one integer _n_ — the number of vertices in the tree (3 ≤ _n_ ≤ 1 000). Each of the next _n_ - 1 lines contains one integer _p__i_ (1 ≤ _i_ ≤ _n_ - 1) — the index of the parent of the _i_ + 1\\-th vertex (1 ≤ _p__i_ ≤ _i_).\n\nVertex 1 is the root. It's guaranteed that the root has at least 2 children."},{"iden":"output","content":"Print \"_Yes_\" if the tree is a spruce and \"_No_\" otherwise."},{"iden":"examples","content":"Input\n\n4\n1\n1\n1\n\nOutput\n\nYes\n\nInput\n\n7\n1\n1\n1\n2\n2\n2\n\nOutput\n\nNo\n\nInput\n\n8\n1\n1\n1\n1\n3\n3\n3\n\nOutput\n\nYes"},{"iden":"note","content":"The first example:\n\n![image](https://espresso.codeforces.com/a028cc3eb93ff24e14e12c093bc7fd0e0d9f7a1a.png)\n\nThe second example:\n\n![image](https://espresso.codeforces.com/e6c7b518972d13e2572004d8ce21cda77de4c938.png)\n\nIt is not a spruce, because the non-leaf vertex 1 has only 2 leaf children.\n\nThe third example:\n\n![image](https://espresso.codeforces.com/9af8f35bd8ce5823176fec24fc464c670bf95c3e.png)"}],"translated_statement":[{"iden":"statement","content":"考虑一棵有根树。有根树有一个特殊的顶点称为根。所有边都从根指向外。如果存在一条从顶点 #cf_span[v] 指向顶点 #cf_span[u] 的有向边，则称顶点 #cf_span[u] 是顶点 #cf_span[v] 的 _子节点_，顶点 #cf_span[v] 是顶点 #cf_span[u] 的 _父节点_。如果一个顶点没有子节点但有父节点，则称其为 _叶子_。\n\n我们称一棵有根树为 _松树_，如果它的每一个非叶子顶点都至少有 #cf_span[3] 个叶子子节点。给你一棵有根树，请判断它是否为松树。\n\n有根树的定义可在此处找到。\n\n第一行包含一个整数 #cf_span[n] —— 树中顶点的数量（#cf_span[3 ≤ n ≤ 1 000]）。接下来的 #cf_span[n - 1] 行每行包含一个整数 #cf_span[pi]（#cf_span[1 ≤ i ≤ n - 1]）—— 第 #cf_span[i + 1] 个顶点的父节点的编号（#cf_span[1 ≤ pi ≤ i]）。\n\n顶点 #cf_span[1] 是根。保证根至少有 #cf_span[2] 个子节点。\n\n如果树是松树，输出 \"_Yes_\"；否则输出 \"_No_\"。\n\n第一个例子：\n\n\n\n第二个例子：\n\n\n\n它不是松树，因为非叶子顶点 #cf_span[1] 只有 #cf_span[2] 个叶子子节点。\n\n第三个例子：\n\n\n\n"},{"iden":"input","content":"第一行包含一个整数 #cf_span[n] —— 树中顶点的数量（#cf_span[3 ≤ n ≤ 1 000]）。接下来的 #cf_span[n - 1] 行每行包含一个整数 #cf_span[pi]（#cf_span[1 ≤ i ≤ n - 1]）—— 第 #cf_span[i + 1] 个顶点的父节点的编号（#cf_span[1 ≤ pi ≤ i]）。顶点 #cf_span[1] 是根。保证根至少有 #cf_span[2] 个子节点。"},{"iden":"output","content":"如果树是松树，输出 \"_Yes_\"；否则输出 \"_No_\"。"},{"iden":"examples","content":"输入\n4\n1\n1\n1\n输出\nYes\n\n输入\n7\n1\n1\n1\n2\n2\n2\n输出\nNo\n\n输入\n8\n1\n1\n1\n1\n3\n3\n3\n输出\nYes"},{"iden":"note","content":"第一个例子：\n\n\n\n第二个例子：\n它不是松树，因为非叶子顶点 #cf_span[1] 只有 #cf_span[2] 个叶子子节点。\n\n第三个例子：\n\n\n\n"}],"sample_group":[],"show_order":[],"formal_statement":"Let $ T = (V, E) $ be a rooted tree with $ n $ vertices, where vertex $ 1 $ is the root.  \nLet $ \\text{parent}(v) $ denote the parent of vertex $ v \\neq 1 $, and $ \\text{children}(v) $ denote the set of children of vertex $ v $.  \n\nA vertex $ v $ is a **leaf** if $ |\\text{children}(v)| = 0 $ and $ v \\neq 1 $.  \nA vertex $ v $ is **non-leaf** if $ |\\text{children}(v)| > 0 $.  \n\nThe tree $ T $ is a **spruce** if every non-leaf vertex has at least 3 leaf children.  \n\nThat is, for all $ v \\in V $ such that $ |\\text{children}(v)| > 0 $:  \n$$\n\\left| \\left\\{ u \\in \\text{children}(v) \\mid |\\text{children}(u)| = 0 \\right\\} \\right| \\geq 3\n$$\n\n**Input:**  \n- Integer $ n $, $ 3 \\leq n \\leq 1000 $  \n- For $ i = 1 $ to $ n-1 $: integer $ p_i $, the parent of vertex $ i+1 $, with $ 1 \\leq p_i \\leq i $\n\n**Output:**  \n\"Yes\" if $ T $ is a spruce; \"No\" otherwise.","simple_statement":null,"has_page_source":false}