https://binarysearch.com/problems/Maximize-the-Number-of-Equivalent-Pairs-After-Swaps
You are given a list of integers of the same length A and B. You are also given a two-dimensional list of integers C where each element is of the form [i, j] which means that you can swap A[i] and A[j] as many times as you want.
Return the maximum number of pairs where A[i] = B[i] after the swapping.
Constraints
-
n ≤ 100,000wherenis the length ofAandB -
m ≤ 100,000wheremis the length ofC
Example 1
Input
A = [1, 2, 3, 4]
B = [2, 1, 4, 3]
C = [ [0, 1], [2, 3] ]
Output
4
Explanation
We can swap A[0] with A[1] then A[2] with A[3].
can someone help me with the approach?