传送门
#include <iostream>
#include <algorithm>using namespace std;
const int N = 1e4 + 10;
int n;
int out[N], par[N], son[N];
int main() {ios::sync_with_stdio(false);cin.tie(), cout.tie();cin >> n;for (int i = 2, root; i <= n; ++i) {cin >> root;par[i] = root;++out[root];}for (int i = 2; i <= n; ++i) {if (out[i] == 0)++son[par[i]];}bool flag = true;for (int i = 1; i <= n; ++i) {if (out[i] != 0 && son[i] < 3){flag = false;break;}}if (flag)cout << "Yes" << endl;elsecout << "No" << endl;return 0;
}
本文发布于:2024-02-02 01:01:43,感谢您对本站的认可!
本文链接:https://www.4u4v.net/it/170681189040389.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
留言与评论(共有 0 条评论) |