3
vector<int> Ar, Ap, Br, Bp; // alice and bob parent and rank arrays4
static bool cmp(vector<int> &a, vector<int> &b) {7
// lets create the alice graph first8
// find function for finding the parent nodes10
if (x == Ap[x]) return x;11
return Ap[x] = find1(Ap[x]);13
// if nodes are already connected return 1 else make the connection and return15
bool union1(int x, int y) {18
if (parX == parY) return 1;19
if (Ar[parX] > Ar[parY]) {21
} else if (Ar[parX] < Ar[parY]) {29
// same thing do for bob graph31
if (x == Bp[x]) return x;32
return Bp[x] = find2(Bp[x]);35
bool union2(int x, int y) {38
if (parX == parY) return 1;39
if (Br[parX] > Br[parY]) {41
} else if (Br[parX] < Br[parY]) {50
int maxNumEdgesToRemove(int n, vector<vector<int>> &edges) {56
for (int i = 0; i < n; i++) {61
sort(edges.begin(), edges.end(), cmp);63
// give priority to 3rd type of vertices64
for (auto a : edges) {65
if (a[0] != 3) continue;66
if (union1(a[1] - 1, a[2] - 1)) ans++;68
union2(a[1] - 1, a[2] - 1);70
// now try the edges one by one and check if it the given nodes are already71
// connected in respective alice and bob graph or not72
for (auto a : edges) {73
if (a[0] == 3) continue;75
if (union1(a[1] - 1, a[2] - 1)) ans++;79
if (union2(a[1] - 1, a[2] - 1)) ans++;82
int cnt1 = 0, cnt2 = 0;83
for (int i = 0; i < n; i++) {84
if (Ap[i] == i) cnt1++;85
if (Bp[i] == i) cnt2++;87
if (cnt1 > 1 | cnt2 > 1) return -1;