C++ UF
\nint ds_find(vector<int>& ds, int p) {\n  return ds[p] == -1 ? p : ds[p] = ds_find(ds, ds[p]);\n}\nvoid ds_merge(vector<int>& ds, int p1, int p2) {\n  p1 = ds_
```\nint ds_find(vector<int>& ds, int p) {\n  return ds[p] == -1 ? p : ds[p] = ds_find(ds, ds[p]);\n}\nvoid ds_merge(vector<int>& ds, int p1, int p2) {\n  p1 = ds_find(ds, p1), p2 = ds_find(ds, p2);\n  if (p1 != p2) ds[max(p1, p2)] = min(p1, p2);\n}\nstring smallestEquivalentString(string A, string B, string S) {\n  vector<int> ds(26, -1);\n  for (auto i = 0; i < A.size(); ++i) ds_merge(ds, A[i] - \'a\', B[i] - \'a\');\n  for (auto i = 0; i < S.size(); ++i) S[i] = ds_find(ds, S[i] - \'a\') + \'a\';\n  return S;\n}\n```
[]