Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- auto unionGroups = [&](int a, int b, int time) {
- int rootA = find(a);
- int rootB = find(b);
- if (rootA != rootB) {
- // If one component is infected, propagate the infection time to the other component
- if (infectionTime[rootA] != -1 && infectionTime[rootB] == -1 && !vaccinated[rootB]) {
- infectionTime[rootB] = time; // Set infection time for rootB
- } else if (infectionTime[rootB] != -1 && infectionTime[rootA] == -1 && !vaccinated[rootA]) {
- infectionTime[rootA] = time; // Set infection time for rootA
- }
- // Merge groups by rank
- if (rank[rootA] > rank[rootB]) {
- parent[rootB] = rootA;
- } else if (rank[rootA] < rank[rootB]) {
- parent[rootA] = rootB;
- } else {
- parent[rootB] = rootA;
- rank[rootA]++;
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement