DoorDashOA #5
Get Sizes of Friends Groups
估计中等可在线判题
考点(AI 标注)并查集
Initially, each person is in a single-person group. F a b merges the groups of the two people; T a b adds the sizes of the two people's groups to a running total. If the two people are already in the same group, the group size is taken separately for each of the two people as the statement says, so it is counted twice. Output the total over all T operations.
输入格式
n q≤100000, followed by q lines, each with F/T and two ID values in 1..n.
输出格式
Output the accumulated value, using a 64-bit integer.
样例 1
输入:
4 3
F 1 2
F 2 3
T 1 4
输出:
4
样例 2
输入:
2 1
T 1 1
输出:
2
样例 3
输入:
3 4
F 1 2
T 1 2
F 1 2
T 1 3
输出:
7