while (pre.size())
{
for (int i = 0; i < pre.size(); i++) {
if(genealogy.find(pre[i])!=genealogy.end())
{
genealogy[post[i]] = genealogy[pre[i]]+1;
pre.erase(pre.begin()+i);post.erase(post.begin()+i);
break;
}
else if(genealogy.find(post[i])!=genealogy.end())
{
genealogy[pre[i]] = genealogy[post[i]]-1;
pre.erase(pre.begin()+i);post.erase(post.begin()+i);
break;
}
}
}