I tried to solve this problem using BFS on priority queue with a custom comparator ,but getting WA ,and I really wanna know if the main idea is wrong or there is something in the code code
struct Compare {
bool operator()(pair<string, int> const& p1, pair<string, int> const& p2)
{
if (p1.first.length() == p2.first.length())
return p1.first > p2.first;
return p1.first.length() > p2.first.length();
}
};








