Simple DFS | C++
\nclass Solution {\n    void dfs(int node, vector<int> adj[], vector<int> &vis, int &mn) {\n        vis[node] = 1;\n        mn = min(mn, node);\n        for(int
```\nclass Solution {\n    void dfs(int node, vector<int> adj[], vector<int> &vis, int &mn) {\n        vis[node] = 1;\n        mn = min(mn, node);\n        for(int ad : adj[node]) {\n            if(!vis[ad]) dfs(ad, adj, vis, mn);\n        }\n    }\npublic:\n    string smallestEquivalentString(string s1, string s2, string baseStr) {\n        int n = s1.size();\n        vector<int> adj[26];\n        for(int i=0; i<n; i++) {\n            adj[s1[i] - \'a\'].push_back(s2[i] - \'a\');\n            adj[s2[i] - \'a\'].push_back(s1[i] - \'a\');\n        }\n\n        vector<int> sol(26);\n        for(char c=\'a\'; c<=\'z\'; c++) {\n            vector<int> vis(26);\n            int mn = 27;\n            dfs(c - \'a\', adj, vis, mn);\n            sol[c - \'a\'] = mn;\n        }\n        \n        string ans;\n        for(char c : baseStr) ans += sol[c - \'a\'] + \'a\';\n        \n        return ans;\n    }\n};\n```
['Depth-First Search', 'Graph', 'C++']