disjoint set stuff working. Need to test that it's correctly optimized
though