304787: CF913B. Christmas Spruce
Memory Limit:256 MB
Time Limit:1 S
Judge Style:Text Compare
Creator:
Submit:0
Solved:0
Description
Christmas Spruce
题意翻译
题意 考虑一颗有根树。一颗有根树有一个叫做根的特殊顶点,所有边的方向都是从根来的。如果有一条从v到u的边,那么顶点v是u的父亲,u是v的孩子。如果一个顶点没有孩子并且有一个父亲,这个顶点叫做叶结点。 如果一颗有根树的每个非叶结点至少有三个是叶结点的孩子,这棵树是一棵云杉。 给你一颗有根树,检查它是否是一棵云杉。 输入格式: 第一行包含一个整数 n(3<=n<=1000),树中的顶点数。 接下来的n-1行每行包含一个整数 p_{i}(1<=i<=n-1,1<=p_{i}<=i),表示第i+1个顶点的父亲。 顶点1为根,保证根最少有两个孩子。 输出格式: 如果它是云杉,输出"Yes",否则,输出 "No"。 Translated by Fowany题目描述
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. Let'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. The definition of a rooted tree can be found [here](https://goo.gl/1dqvzz).输入输出格式
输入格式
The first line contains one integer $ n $ — the number of vertices in the tree ( $ 3<=n<=1000 $ ). 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 $ ). Vertex $ 1 $ is the root. It's guaranteed that the root has at least $ 2 $ children.
输出格式
Print "Yes" if the tree is a spruce and "No" otherwise.
输入输出样例
输入样例 #1
4
1
1
1
输出样例 #1
Yes
输入样例 #2
7
1
1
1
2
2
2
输出样例 #2
No
输入样例 #3
8
1
1
1
1
3
3
3
输出样例 #3
Yes