Answers for "disjoint set data structure cp algorithms"

0

disjoint set data structure cp algorithms

void make_set(int v) {
    parent[v] = v;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b)
        parent[b] = a;
}
Posted by: Guest on March-22-2021

Browse Popular Code Answers by Language