USING GRAPHS BUT GETTING TIME LIMIT EXCEEDED.
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int mod=1e9+7;\n\n    void csc(vector<string> &v, int m, int i, string s) {\n        // Base Case: if we have formed a string of length m, we add it to the list and return\n        if (i == m) {\n            v.push_back(s);\n            return;\n        }\n        \n        // Ensure we are not adding the same character consecutively\n        if (i == 0 || s[i-1] != \'0\') {\n            csc(v, m, i + 1, s + \'0\');\n        }\n        if (i == 0 || s[i-1] != \'1\') {\n            csc(v, m, i + 1, s + \'1\');\n        }\n        if (i == 0 || s[i-1] != \'2\') {\n            csc(v, m, i + 1, s + \'2\');\n        }\n    }\n\n    void bfs(vector<vector<int>> &v, int src, int parent, int &count, int n, int c) {\n        if (c == n) {\n            count = (count + 1) % mod;\n            return;\n        }\n        for (int i = 0; i < v[src].size(); ++i) {\n            //if (v[src][i] != parent) {\n                bfs(v, v[src][i], src, count, n, c + 1);\n            //}\n        }\n    }\n \n    int colorTheGrid(int m, int n) {\n        vector<string> v;\n        string s;\n        csc(v, m, 0, s);\n        \n        int x = v.size();\n        vector<vector<int>> adj(x);\n        \n        for (int i = 0; i < x; ++i) {\n            for (int j = i + 1; j < x; ++j) {\n                bool b = true;\n                for (int k = 0; k < m; ++k) {\n                    if (v[i][k] == v[j][k]) {\n                        b = false;\n                        break;\n                    }\n                }\n                if (b) {\n                    adj[i].push_back(j);\n                    adj[j].push_back(i);\n                }\n            }\n        }\n\n        int count = 0;\n        for (int i = 0; i < x; ++i) {\n            bfs(adj, i, -1, count, n, 1);\n            count = count % mod;\n        }\n        return count;\n    }\n};\n```
['Dynamic Programming', 'Graph', 'C++']