Use disjoint-set/union-find for connected components, instead of breadth-first search:
https://bugfix-66.com/5c92ae4bfe4b19be55b1f8136d7f844b630fa8...
Above is the most efficient known disjoint-set algorithm: Martin Rem's union-find.
https://bugfix-66.com/5c92ae4bfe4b19be55b1f8136d7f844b630fa8...
Above is the most efficient known disjoint-set algorithm: Martin Rem's union-find.