Basically, I am trying to modify Kruskal's algorithm by adding one more condition besides checking whether vertices u and v are not in the same component. I vaguely understand how union-find data structure works, so I wanted to check if I actually got the right idea.
Given that I have an undirected graph G = (V, E) and a set A that contains some vertices in V (subset of vertices A ⊂ V), I want to catch the instances where, for each vertex u in V (loop), u is also found in this set A. I was thinking of using:
(Full Kruskal's algorithm omitted)
original_comp = make_sets(V)
A_comp = make_sets(A)
for each edge (u, v) in E:
if (find(original_comp, u) == find(A_comp, u)):
// do something
Would this not work because the set parameter is different (thus different labels)? I just wanted to confirm...
To clarify, I need to know if an edge (u, v) contains one of the vertices in set A. And I was trying to use the Union-Find to achieve this (since find() takes O(1) time), instead of traversing the set A to compare each element... Could anyone tell me if this is possible? Or should I just use an array traversal method?
Thank you.