Gooooogle • 6个月前
#include<iostream>
using namespace std;
int res=0;
void tree(int t,bool isLeftSon)
{
int left,right;
cin>>left;
if(left!=-1)
tree(left,1);
cin>>right;
if(right!=-1)
tree(right,0);
if(left==-1&&right==-1&&isLeftSon)
res+=t;
return;
}
int main()
{
int t;
cin>>t;
tree(t,0);
cout<<res;
return 0;
}
评论:
请先登录,才能进行评论