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) {
- // Merge lower rank root into higher rank root
- if (rank[rootA] > rank[rootB]) {
- parent[rootB] = rootA;
- if (infectionTime[rootA] != -1 && infectionTime[rootB] == -1 && !vaccinated[rootB]) {
- infectionTime[rootB] = time;
- }
- } else if (rank[rootA] < rank[rootB]) {
- parent[rootA] = rootB;
- if (infectionTime[rootB] != -1 && infectionTime[rootA] == -1 && !vaccinated[rootA]) {
- infectionTime[rootA] = time;
- }
- } else {
- parent[rootB] = rootA;
- rank[rootA]++;
- if (infectionTime[rootA] != -1 && infectionTime[rootB] == -1 && !vaccinated[rootB]) {
- infectionTime[rootB] = time;
- } else if (infectionTime[rootB] != -1 && infectionTime[rootA] == -1 && !vaccinated[rootA]) {
- infectionTime[rootA] = time;
- }
- }
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement