#include #include "set.h" set *set_create() { set *s = malloc(sizeof(set)); s->parent = s; s->rank = 0; return s; } void set_free(set *s) { free(s); } set *set_find(set *s) { if(s->parent == s) return s; s->parent = set_find(s->parent); return s->parent; } void set_union(set *x, set *y) { x = set_find(x); y = set_find(y); if(x == y) return; if(x->rank > y->rank) { y->parent = x; } else { x->parent = y; } if(x->rank == y->rank) x->rank++; }