Submission
Status:
[PPPPPPPPPP]
Subtask/Task Score:
{100/100}
Score: 100
User: 12345678
Problemset: composite tree
Language: cpp
Time: 0.002 second
Submitted On: 2025-11-18 10:57:23
#include <bits/stdc++.h>
using namespace std;
int idx;
string s;
struct tree
{
struct node
{
int vl;
node *l, *r;
node(int vl=0): vl(vl), l(0), r(0){}
};
typedef node* pnode;
pnode rta, rtb;
void build(pnode &k)
{
if (s[idx]==')') return idx++, void();
// cout<<"debug "<<idx<<' '<<s[idx]-'0'<<'\n';
k=new node(s[idx++]-'0');
idx++;
build(k->l);
idx++;
build(k->r);
idx++;
}
void show(pnode x, pnode y)
{
if (!x||!y) return cout<<")", void();
cout<<x->vl+y->vl;
cout<<"(";
show(x->l, y->l);
cout<<"(";
show(x->r, y->r);
if (x!=rta) cout<<")";
}
} t;
int main()
{
cin.tie(NULL)->sync_with_stdio(false);
cin>>s;
idx=0;
t.build(t.rta);
cin>>s;
idx=0;
t.build(t.rtb);
t.show(t.rta, t.rtb);
}
/*
5(2(8()())())(1(6(2()())(3()()))())
3(4()())(8(1(2()())())(3()()))
*/