Maximize the Number of Equivalent Pairs After Swaps
题目地址(690. 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,000 where n is the length of A and B
m ≤ 100,000 where m is the length of C
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].前置知识
并查集
思路
代码
总结
最后更新于
这有帮助吗?