DFS (connected components) C++ solution
\n\n# Code\n\nclass Solution {\npublic:\n    #define pii pair<int,int>\n\n    string ans;\n    vector<bool> visited;\n\n    void dfs(vector<vector<int>>& adj, i
\n\n# Code\n```\nclass Solution {\npublic:\n    #define pii pair<int,int>\n\n    string ans;\n    vector<bool> visited;\n\n    void dfs(vector<vector<int>>& adj, int i=0, int val=0)\n    {\n        visited[i]=true;\n        ans[i]= \'a\'+ val;\n        for(auto it: adj[i])\n        {\n            if(!visited[it]) dfs(adj, it, val);\n        }\n    }\n    string findTheString(vector<vector<int>>& lcp) {\n        \n        // i want to know the equalities\n        int n= lcp.size();\n        vector<vector<int>> v(n);\n        set<pii> st;\n        for(int i=0;i<n;i++)\n        {\n            int dist;\n            for(int j=0;j<n;j++)\n            {\n                if(lcp[i][i] != n-i) return "";\n                if(lcp[i][j] != lcp[j][i]) return "";\n                if(i-1 >=0 && j-1 >=0 && lcp[i-1][j-1] > 0 && lcp[i][j] + 1 != lcp[i-1][j-1]) return "";\n                dist= min(n-i, n-j);\n               \n                if(lcp[i][j] > dist) return "";\n\n                if(st.find({i, j})== st.end() && st.find({j,i})== st.end() && lcp[i][j] !=0) \n                {\n                    v[i].push_back(j);\n                    v[j].push_back(i);\n                }\n                st.insert({i,j});\n            \n            }\n        }\n        ans.resize(n);\n        visited.resize(n, false);\n        int val=0;\n        for(int i=0;i<n;i++)\n        {\n            if(!visited[i]) {if(val>25) return ""; dfs(v, i, val); val++;}\n        \n        }\n\n        return ans;\n    }\n};\n```
['C++']