POJ - 1635 Subway tree systems
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
string dfs(string &a, int &u)
{
u++;
vector<string> b;
while(a[u]=='0') b.push_back(dfs(a,u));
u++;
sort(b.begin(),b.end());
string res="0";
for(int i=0;i<b.size();i++) res+=b[i];
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;
}
return 0;
}