static L clusters_add(Map> clusters, L l) {
for (int i = 0; i < l(l)-1; i++)
clusters_add(clusters, l.get(i), l.get(i+1));
ret clusters.get(first(l));
}
static void clusters_add(Map> clusters, A a, A b) {
if (eq(a, b)) {
L cluster = clusters.get(a);
if (cluster == null)
clusters.put(a, litlist(a));
ret;
}
L clusterA = clusters.get(a);
L clusterB = clusters.get(b);
if (clusterA == null && clusterB == null) {
L cluster = ll(a, b);
clusters.put(a, cluster);
clusters.put(b, cluster);
} else if (clusterA == null) {
clusterB.add(a);
clusters.put(a, clusterB);
} else if (clusterB == null) {
clusterA.add(b);
clusters.put(b, clusterA);
} else if (clusterA != clusterB)
clusters_merge(clusters, clusterA, clusterB);
}