题解
犯了对变量定义不清晰的错误
code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll a[300005]={0};
vector<int> G[1005];
int dp[1005]={0};//当前节点的叶子节点的数量
int flag=1;
void dfs(int now)
{
for(auto next:G[now])
{
dfs(next);
dp[now]+=(G[next].size()==0);//判断叶子节点
}
flag&=(dp[now]>=3||G[now].size()==0);
}
int main()
{
int t=1;
//cin>>t;
while(t--)
{
int n;
cin>>n;
for(int i=2;i<=n;i++)
{
int x;
cin>>x;
G[x].push_back(i);
}
dfs(1);
puts(flag?"Yes":"No");
}
return 0;
}
标签:int,dfs,next,flag,Spruce,now,Christmas,dp
From: https://www.cnblogs.com/pure4knowledge/p/18196516