booldfs(vector<vector<char> > &board, int x, int y, TrieNode *root, unordered_set<string> &res) { char ch = board[x][y]; if (!root->children.count(ch)) { returnfalse; } root = root->children[ch]; if (root->word.size() > 0) { res.insert(root->word); }
board[x][y] = '#'; for (int i = 0; i < 4; ++i) { int nx = x + dirs[i][0]; int ny = y + dirs[i][1]; if (nx >= 0 && nx < board.size() && ny >= 0 && ny < board[0].size()) { if (board[nx][ny] != '#') { dfs(board, nx, ny, root, res); } } } board[x][y] = ch;