1class Solution {2unordered_map<string, vector<char>> m;34public:5bool dfs(string bot, int i, string tem) {6if (bot.size() == 1) return true;7if (i == bot.size() - 1) {8string st;9return dfs(tem, 0, st);10}11for (auto v : m[bot.substr(i, 2)]) {12tem.push_back(v);13if (dfs(bot, i + 1, tem)) {14return true;15}16tem.pop_back();17}18return false;19}20bool pyramidTransition(string bottom, vector<string> &allowed) {21for (auto a : allowed) {22m[a.substr(0, 2)].push_back(a[2]);23}24string te;25return dfs(bottom, 0, te);26}27};