链接
传送门
代码
#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;
else
cout << "No" << endl;
return 0;
}