#include
#include
#include
#include
using namespace std;
class node{
public:
int data ;
nodeleft;
noderight;
node( int d){
data = d;
left = NULL;
right = NULL;
}
};
nodetemp = NULL;
nodebuildtree(){
string s;cin>>s;
if(s==“false”){
return NULL;
}
if(s==“true”){
buildtree();
}
if(s!= “true”&&s!= “false”){
noderoot = new node(stoi(s));
root->left = buildtree();
root->right = buildtree();
temp = root;
}
return temp;
}
vectorV;
bool roottoleaf(noderoot, int k){
if(root == NULL){
return false;
}
int subsum = k - root->data;
if( subsum == 0){
V.push_back(root->data);
return true;
}
bool a = roottoleaf(root->left,subsum);
bool b = roottoleaf(root->right,subsum);
if(a || b){
V.push_back(root->data);
}
return a ||b;
}
int main() {
node*root = buildtree();
int k;
cin >>k;
roottoleaf(root,k);
reverse(V.begin(),V.end());
for( int i = 0; i < V.size(); i++){
cout << V[i] << " ";
}
return 0;
}