MCPcopy Create free account
hub / github.com/codemistic/Data-Structures-and-Algorithms / union_num

Function union_num

disjoint set - Copy/code.cpp:22–43  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

20}
21
22void union_num(vector<int> &parent, vector<int> &rank, int num1, int num2)
23{
24 int fparent = find(parent, num1);
25 int sparent = find(parent, num2);
26 if (fparent == sparent)
27 {
28 return;
29 }
30 if (rank[fparent] < rank[sparent])
31 {
32 parent[fparent] = sparent;
33 }
34 else if (rank[fparent] > rank[sparent])
35 {
36 parent[sparent] = fparent;
37 }
38 else
39 {
40 parent[fparent] = sparent;
41 rank[sparent]++;
42 }
43}
44
45void solve()
46{

Callers 1

solveFunction · 0.85

Calls 1

findFunction · 0.70

Tested by

no test coverage detected