解析:
树的最小表示法:对于每个节点的最小表示法为子节点的最小表示法排序连接起来
最终都是通过排序连接。0表示向下走,1表示向上走
#include<bits/stdc++.h>
using namespace std;
string dfs(string &seq, int &u)
{
u ++ ;
vector<string> seqs;
while (seq[u] == '0') seqs.push_back(dfs(seq, u));
u ++ ;
sort(seqs.begin(), seqs.end());
string res = "0";
for (auto &s : seqs) res += s;
res += '1';
return res;
}
int main()
{
int t;
cin>>t;
while(t--)
{
string a,b;
cin>>a>>b;
a='0'+a+'1';
b='0'+b+'1';
int ua=0,ub=0;
if(dfs(a,ua)==dfs(b,ub)) cout<<"same"<<endl;
else cout<<"different"<<endl;
}
}