6 lines clean Unicode-Find
\ndef makeConnected(self, n, connections):\n    if len(connections) < n - 1:\n        return -1\n    s = \'\'.join(map(chr, range(n)))\n    for a, b in connecti
```\ndef makeConnected(self, n, connections):\n    if len(connections) < n - 1:\n        return -1\n    s = \'\'.join(map(chr, range(n)))\n    for a, b in connections:\n        s = s.replace(s[a], s[b])\n    return len(set(s)) - 1\n```\nPython 3, accepted in 940 ms. Union-Find but with a silly data structure: A string `s` where `s[i]` tells me the current component of computer `i`. As a unicode character. Initially the components (i.e., characters) are all different, but then I join components by turning members of component `s[a]` into members of component `s[b]`.\n\n(I had written a faster solution first, but then I saw that basically the same had already been posted by @lee215)
[]