----下面的是gay---- • 1天前
using namespace std; struct node{
int data;
int l,r;
}; node tr1[1005]; node tr2[1005]; int tree1[1005]; int tree2[1005]; int t=0,t1=0,m; int cur=0; bool cmp=0; int dfs(){
int x;
cin>>x;
if(x==-1){
return -1;
}
int cnt=cur++;
tr1[cnt].data=x;
tr1[cnt].l=dfs();
tr1[cnt].r=dfs();
return cnt;
} void dfs2(int root,int sum){
if(root==-1){
if(sum==m){
cmp=1;
}
return;
}
if(tr1[root].l==-1 && tr1[root].r==-1){
tree1[t++]=tr1[root].data;
}
dfs2(tr1[root].l,sum+tr1[root].data);
dfs2(tr1[root].r,sum+tr1[root].data);
return;
} int main(){
int root1=dfs();
cin>>m;
dfs2(root1,0);
if(cmp){
cout<<"yes"<<endl;
return 0;
}else{
cout<<"no"<<endl;
}
return 0;
}
评论:
请先登录,才能进行评论